1

im trying to create a google chart using mysql and PHP, after doing an extensive research, i managed to find ways do display the charts however this work on vertical tables.

the current table that im using has the id,date on the first column, below is a sample output

+----+------------+------------+--------------+
| id | DATE       | COL1       |     COL2     |
+----+------------+------------+--------------+
|  1 | 18/04/2016 |     5291   |       2217   |
+----+------------+------------+--------------+

i've used the solution provided here and below is the code sample:

  $result = $mysqli->query('SELECT * FROM Statistics limit 3');

  $rows = array();
  $table = array();
  $table['cols'] = array(

    array('label' => 'COL1', 'type' => 'number'),
    array('label' => 'COL2', 'type' => 'number')

);

    foreach($result as $r) {

      $temp = array();
      $temp[] = array('v' => (string) $r['COL1']); 
      $temp[] = array('v' => (int) $r['COL2']); 
      $rows[] = array('c' => $temp);
    }

$table['rows'] = $rows;


$jsonTable = json_encode($table);

print $jsonTable;

however when using pi chart for example, it'll use the values from COL1 only and ignores the rest...

Thanks, Ali

Community
  • 1
  • 1
Ali Jaber
  • 75
  • 1
  • 1
  • 7

0 Answers0