title: How to create Google Chart friendly JSON arrays from MySQL?
body: <p>I think I'm close to completing the passing of MySQL data to Google Charts through JSON/AJAX. I am able to output a JSON string in the correct format but it is not outputting any SQL data. I've searched everywhere for a solution with no results. Anyone see what is missing from the code?</p>
  
  <p><strong>JSON output</strong></p>
  
  <pre><code>{"cols":[{"id":"","label":"projid","type":"string"},{"id":"","label":"hours","type":"number"}],"rows":[{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]}]}
  </code></pre>
  
  <p><strong>PHP->JSON</strong></p>
  
  <pre><code>&lt;?php
  // -----&gt; Query MySQL and parse into JSON below. &lt;------
  
  // write your SQL query here (you may use parameters from $_GET or $_POST if you need them)
  
  require_once ("Includes/session.php");
  require_once ("Includes/simplecms-config.php");
  require_once ("Includes/connectDB.php");
  
  $recId = null;
  $projid = null;
  $hours = null;
  
          $recId = $_GET['id'];
          $projid = $_GET['projid'];
          $hours = $_GET['hours'];
          $query = "SELECT projid, hours FROM hours WHERE id = ?";
          $statement = $databaseConnection-&gt;prepare($query);
          $statement-&gt;bind_param('d', $recId);
          $statement-&gt;execute();
          $results = $statement-&gt;get_result();
  
    $rows = array();
    $table = array();
    $table['cols'] = array(
      array('id' =&gt; "",'label' =&gt; 'projid', 'type' =&gt; 'string'),
      array('id' =&gt; "",'label' =&gt; 'hours', 'type' =&gt; 'number')
  );
  
  
      /* Extract the information from $result */
      while ($r = $results-&gt;fetch_assoc()) {
        $temp = array();
  
        // The following line will be used to slice the Pie chart
        $temp[] = array('v' =&gt; (string) $r['projid']); 
  
        // Values of each slice
        $temp[] = array('v' =&gt; (int) $r['hours']); 
        $rows[] = array('c' =&gt; $temp);
      }
  
  $table['rows'] = $rows;
  
  // convert data into JSON format
  $jsonTable = json_encode($table);
  echo $jsonTable;
  </code></pre>
  
  <p>?></p>