title: convert mysql resultset into a (name, data) object to be fed into HighCharts
body: <p>I am using <a href="http://www.highcharts.com/demo/bar-basic" rel="nofollow">HighCharts Bar graph</a> to plot data from mysql resultset into a bar graph.</p>
  
  <p>Now the resultset of my query is as below:</p>
  
  <pre><code>Name       Expense
  -----------------
  July       700.0000
  August     450.0000  
  September  1700.0000
  </code></pre>
  
  <p>The <code>series</code> property of HighCharts require data in below format to plot the graph</p>
  
  <pre><code>[
   {name:"July",data:[700.0000]},
   {name:"August",data:[450.0000]},
   {name:"September",data:[1700.0000]}
  ] 
  </code></pre>
  
  <p>So I thought of coverting my resultset into a JSON object using <code>json_encode($row)</code>.
  But I got the following output:</p>
  
  <pre><code>[{"name":"July","data":"700.0000"},
   {"name":"August","data":"450.0000"},
   {"name":"September","data":"1700.0000"}] 
  </code></pre>
  
  <p><strong>Doubts:</strong></p>
  
  <ol>
  <li>Is there a way to get/convert the resultset in exactly the same format as is required by the series property of HighCharts?</li>
  <li><p>Also can I use an object of created in the php block, directly into the javascript? Say I create an object <code>$jsonNameData</code> out of my resultset. Then can I use it in the javascript as </p>
  
  <p><code>series: &lt;? echo $jsonNameData ?&gt;</code></p></li>
  </ol>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I was able to solve Q1 by doing the following:</p>
  
  <pre><code>$count = 0;
  $strSeries = "[";
  while($r = mysql_fetch_assoc($result)) {
  
     if($count == 0){
         $strSeries .= "{name:'" . $r['name'] . "',";
         $strSeries .= "data:[" . $r['data'] . ']}';
         $count = 1;
     }
     else {
         $strSeries .= ",{name:'" . $r['name'] . "',";
         $strSeries .= "data:[" . $r['data'] . ']}';
     }
   $rows[] = $r;
  }
  $strSeries .= "]";
  </code></pre>
  
  <p>Got the required string into <code>$strSeries</code>.</p>
  
  <p>Now the problem is the second question. I assigned the value of <code>$strSeries</code> to a variable in javascript but when I use that variable as </p>
  
  <pre><code>series: variableName
  </code></pre>
  
  <p>It is not plotting the graph properly even though the variable has proper value (checked through alert).</p>