Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors','1');
- error_reporting(E_ALL);
- $servername = "localhost";
- $username = "root";
- $password = "";
- // Create connection
- $conn = new mysqli($servername, $username, $password ,'test');
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT count(busyness) as total,busyness as label FROM test group by busyness";
- $result = $conn->query($sql);
- $arr = (object )['cols'];
- $arr = (object)['rows'];
- $obj = json_decode(json_encode($arr));
- $obj = (object) array(
- 'cols'=>array(0=>(object) array('id'=>'',
- 'label'=>'Topping',
- 'pattern'=>'',
- 'type'=>'string'
- ),
- 1=>(object) array(
- 'id'=>'',
- 'label'=>'Slices',
- 'pattern'=>'',
- 'type'=>'number'
- )
- ),
- 'rows'=>array(),
- );
- if ($result->num_rows > 0) {
- $i= 0;
- // output data of each row
- while($row = $result->fetch_assoc()) {
- $obj->rows[$i] = (object) array('c'=> array(
- 0=> (object) array('v'=>$row['label'].'%','f'=> null) ,
- 1=> (object)array('v'=> $row['total'],'f'=>null))
- );
- $i=$i+1;
- }
- } else {
- echo "0 results";
- }
- echo json_encode($obj);die;
- //echo '<pre>';
- //print_r($obj);die;
- // This is just an example of reading server side data and sending it to the client.
- // It reads a json formatted text file and outputs it.
- $string = file_get_contents("sampleData.json");
- echo $string;
- // Instead you can query your database and parse into JSON etc etc
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement