Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. +----+------------+----------+-----------------+----------
  2. | ID | DATE | Time | Create | Delete | Product |
  3. +----+------------+----------+-----------------+---------+
  4. | 1 | 03/12/2017 | 09:00:00 | 28 | 1264 | 59 |
  5.  
  6. <?php
  7.  
  8. $DB_NAME = 'testDB';
  9. $DB_HOST = 'localhost';
  10. $db_port = '3306';
  11. $DB_USER = 'test';
  12. $DB_PASS = 'mysql';
  13. $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
  14.  
  15. if (mysqli_connect_errno()) {
  16. printf("Connect failed: %sn", mysqli_connect_error());
  17. exit();
  18. }
  19.  
  20. $result = $mysqli->query('Select * from (SELECT * FROM Stats ORDER BY id DESC LIMIT 48)t ORDER BY id ASC');
  21. $rows = array();
  22. $table = array();
  23. $table['cols'] = array(
  24. array('label' => 'Time', 'type' => 'string'),
  25. array('label' => 'ProductCreate', 'type' => 'number'),
  26. array('label' => 'ProductDelete', 'type' => 'number'),
  27. array('label' => 'ProductRenew', 'type' => 'number')
  28.  
  29. );
  30. foreach($result as $r) {
  31.  
  32. $temp = array();
  33.  
  34. $temp[] = array('v' => (string) $r['Time']);
  35. $temp[] = array('v' => (int) $r['Create']);
  36. $temp[] = array('v' => (int) $r['Delete']);
  37. $temp[] = array('v' => (int) $r['Renew']);
  38.  
  39. $rows[] = array('c' => $temp);
  40. }
  41.  
  42. $table['rows'] = $rows;
  43.  
  44. // convert data into JSON format
  45. $SubsStats = json_encode($table);
  46. echo $SubsStats;
  47.  
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement