Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $DB_NAME = 'master';
- $DB_HOST = 'localhost';
- $DB_USER = 'root';
- $DB_PASS = 'root';
- $conn = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME) or die("Error " . mysqli_error($conn));
- $query = "SELECT topping, slices FROM pizza";
- $result = mysqli_query($conn, $query) or die("Error in Selecting " . mysqli_error($conn));
- $table = array();
- $table['cols'] = array(
- //Labels for the chart, these represent the column titles
- array('id' => '', 'label' => 'topping', 'type' => 'string'),
- array('id' => '', 'label' => 'slices', 'type' => 'number')
- );
- $rows = array();
- while($row = $result->fetch_assoc()){
- $temp = array();
- //Values
- $temp[] = array('v' => (string)$row['topping']);
- $temp[] = array('v' => (float) $row['slices']);
- $rows[] = array('c' => $temp);
- }
- $result->free();
- $table['rows'] = $rows;
- mysqli_close($conn);
- $jsonTable = json_encode($table, true);
- header("Content-Type: application/json");
- echo $jsonTable;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement