title: json_encode a MySQL query for a multi-series flot chart
body: <p>I'm trying to pass a MySQL query to flot chart in the json format specified in the documentation i.e </p>
  
  <pre><code>[ { label: "Foo", data: [ [10, 1], [17, -14], [30, 5] ] },
    { label: "Bar", data: [ [11, 13], [19, 11], [30, -7] ] }
  ]
  </code></pre>
  
  <p>This is my current code:</p>
  
  <pre><code>&lt;?php
  // Connect to MySQL and select database.
  
      require_once 'php/db_login.php';
  
      $db_server = mysql_connect($db_hostname, $db_username, $db_password);
          if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
  
      mysql_select_db($db_database)
          or die("Unable to select: ". mysql_error()); 
  
  $result = mysql_query("SELECT ID,Total,CCGT FROM generation ORDER BY id DESC LIMIT 13");
  
  
  while ($row=mysql_fetch_assoc($result)) 
  {
      $dataset1['label']= 'Total';
      $dataset1['data'] = array($row['ID'],$row['Total'],$row['CCGT']);
  }
  
  echo json_encode($dataset1);
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code>{"label":"Total","data":["494","38431","12"]}
  </code></pre>
  
  <p>This is obviously wrong as it's in the wrong format and it only iterates though 1 result instead of 13. I've tried multiple code examples online but none of them produce the JSON format I'm looking for. All help gratefully received. </p>