SHARE
TWEET

Untitled

a guest Jun 15th, 2017 193 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $server = "localhost";
  3. $userName = "root";
  4. $password = "";
  5. $databaseName = "CPUmonitor";
  6. $currentTime = time();
  7. $tableName = $_POST['tableName'];
  8. $min = $_POST['min'];
  9. $max = $_POST['max'];
  10. $live = $_POST['live'];
  11. if($live == 1) {
  12.     $live = True;
  13. }
  14. else {
  15.     $live = False;
  16. }
  17. $liveRange = $_POST['liveRange'];
  18.  
  19. $conn = mysqli_connect($server, $userName, $password) or die('Error connecting to server');
  20.  
  21. mysqli_select_db($conn, $databaseName);
  22.  
  23. $columns = array();
  24. $table = array();
  25. $table['cols'] = array();
  26. $sql = "SHOW COLUMNS FROM ".$tableName;
  27. $result = mysqli_query($conn,$sql);
  28. while($thing = mysqli_fetch_array($result)){
  29.     array_push($table['cols'],array("label"=>$thing['Field'],"type"=>"number"));
  30.     array_push($columns,$thing['Field']);
  31. }
  32. //$query = mysqli_query($conn,"SELECT * FROM myVM");
  33. if($live) {
  34.     $query = mysqli_query($conn, "SELECT * FROM ".$tableName." ORDER BY time DESC LIMIT ".$liveRange);
  35. }
  36. else {
  37.     $query = mysqli_query($conn, "SELECT * FROM ".$tableName." WHERE time BETWEEN ".$min." AND ".$max);
  38. }
  39. $rows = array();
  40. while($r = mysqli_fetch_assoc($query)) {
  41.     $temp = array();
  42.     for($i = 0; $i < count($columns); $i++) {
  43.         array_push($temp, array("v" => (float)$r[$columns[$i]]));
  44.     }
  45.     array_push($rows, array("c" => $temp));
  46. }
  47.  
  48. $table['rows'] = $rows;
  49.  
  50. $jsonTable = json_encode($table, true);
  51. echo $jsonTable;
  52.  
  53. exit();
  54. ?>
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