title: Javascript and PHP using For loop
body: <p>I have the following code that will output a line chart as follows :</p>
  
  <pre><code>&lt;script class="code" type="text/javascript"&gt;
  $(document).ready(function(){
  
  var line1=[['2008-08-12 ',14], ['2008-09-12 ',6.5], ['2008-10-12 ',5.7], ['2008-11-12 ',9], ['2008-12-12 ',8.2]];
  
   var plot1 = $.jqplot('chart1', [line1], {
      title:'Daily Sales',
      axes:{
          xaxis:{
              renderer:$.jqplot.DateAxisRenderer
          }
      },
      series:[{lineWidth:4, markerOptions:{style:'square'}}]
    });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>The output for the above code is correct, but i want to insert a PHP loop to select data from mysql and place it insde <code>var line1</code> as an array</p>
  
  <p>So I created a test code as follows :</p>
  
  <pre><code>&lt;script class="code" type="text/javascript"&gt;
  $(document).ready(function(){
  
  
  &lt;?php
  
  
      $date = date('Y-m-d');
      for($i=1;$i&lt;6;$i++){
  
      $newdate = strtotime ( '+1 month' , strtotime ( $date ) ) ;
      $newdate = date ( 'Y-m-j' , $newdate ); 
  ?&gt;
      var line1=[['&lt;?php echo $newdate; ?&gt; ',&lt;?php echo $i ?&gt;]];
  
  &lt;?php
      $date = $newdate;
  }
  ?&gt;
  
  
    var plot1 = $.jqplot('chart1', [line1], {
      title:'Daily Sales',
      axes:{
          xaxis:{
              renderer:$.jqplot.DateAxisRenderer
          }
      },
      series:[{lineWidth:4, markerOptions:{style:'square'}}]
    });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>This outputs the last value which is <strong>2015-5-16</strong> and <strong>5</strong> all i want is to output all the result from 1 to 5 and having dates incremented by each month 2014-12-16 to 2015-5-16.</p>
  
  <p>I hope this makes sense ! Thank You</p>