SHARE
TWEET

Untitled

a guest Dec 6th, 2016 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     $DB_NAME = 'master';
  3.     $DB_HOST = 'localhost';
  4.     $DB_USER = 'root';
  5.     $DB_PASS = 'root';
  6.    
  7.     $conn  = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME) or die("Error " . mysqli_error($conn));
  8.    
  9.     $query = "SELECT topping, slices FROM pizza";
  10.    
  11.     $result = mysqli_query($conn, $query) or die("Error in Selecting " . mysqli_error($conn));
  12.     $table = array();
  13.     $table['cols'] = array(
  14.     //Labels for the chart, these represent the column titles
  15.     array('id' => '', 'label' => 'topping', 'type' => 'string'),
  16.     array('id' => '', 'label' => 'slices', 'type' => 'number')
  17.     );
  18.     $rows = array();
  19.     while($row = $result->fetch_assoc()){
  20.         $temp = array();
  21.         //Values
  22.         $temp[] = array('v' => (string)$row['topping']);
  23.         $temp[] = array('v' => (float) $row['slices']);
  24.         $rows[] = array('c' => $temp);
  25.     }
  26.     $result->free();
  27.  
  28.     $table['rows'] = $rows;
  29.     mysqli_close($conn);
  30.     $jsonTable = json_encode($table, true);
  31.     header("Content-Type: application/json");
  32.     echo $jsonTable;
  33.  
  34. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top