Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors','1');
  3. error_reporting(E_ALL);
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7.  
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password ,'test');
  10.  
  11. // Check connection
  12. if ($conn->connect_error) {
  13. die("Connection failed: " . $conn->connect_error);
  14. }
  15. $sql = "SELECT count(busyness) as total,busyness as label FROM test group by busyness";
  16. $result = $conn->query($sql);
  17.  
  18. $arr = (object )['cols'];
  19. $arr = (object)['rows'];
  20. $obj = json_decode(json_encode($arr));
  21.  
  22.  
  23. $obj = (object) array(
  24. 'cols'=>array(0=>(object) array('id'=>'',
  25. 'label'=>'Topping',
  26. 'pattern'=>'',
  27. 'type'=>'string'
  28. ),
  29. 1=>(object) array(
  30. 'id'=>'',
  31. 'label'=>'Slices',
  32. 'pattern'=>'',
  33. 'type'=>'number'
  34.  
  35. )
  36. ),
  37. 'rows'=>array(),
  38. );
  39.  
  40. if ($result->num_rows > 0) {
  41. $i= 0;
  42. // output data of each row
  43. while($row = $result->fetch_assoc()) {
  44. $obj->rows[$i] = (object) array('c'=> array(
  45. 0=> (object) array('v'=>$row['label'].'%','f'=> null) ,
  46. 1=> (object)array('v'=> $row['total'],'f'=>null))
  47.  
  48. );
  49. $i=$i+1;
  50. }
  51. } else {
  52. echo "0 results";
  53. }
  54. echo json_encode($obj);die;
  55. //echo '<pre>';
  56. //print_r($obj);die;
  57. // This is just an example of reading server side data and sending it to the client.
  58. // It reads a json formatted text file and outputs it.
  59.  
  60. $string = file_get_contents("sampleData.json");
  61. echo $string;
  62.  
  63. // Instead you can query your database and parse into JSON etc etc
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement