Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4.     $dataarrayfinal= array();
  5.     $servername = "localhost";
  6.     $username = "root";
  7.     $password = "admin";
  8.     $dbname = "wetterstation";
  9.  
  10.     // Create connection
  11.     $conn = new mysqli($servername, $username, $password, $dbname);
  12.  
  13.  
  14. $sql_temp_sensor = "Select data.temperature, data.humidity FROM (SELECT `temperature`, `humidity`, `timestamp` FROM `test` ORDER BY `timestamp` DESC LIMIT 50) as `data` ORDER BY `data`.`timestamp` ASC";
  15.     $result_temp = $conn->query($sql_temp_sensor);
  16.     // ----------------- FETCH Temp Data -----------------------------
  17.     if ($result_temp->num_rows > 0) {
  18.         // output data of each row
  19.         while($row = $result_temp->fetch_assoc()) {
  20.             $temperature = $row["temperature"];
  21.             $humidity = $row["humidity"];
  22.             $dataarray = array('temperature' => $temeparture, 'humidity' => $humidity);
  23.             array_push($dataarrayfinal, $dataarray);
  24.         }
  25.     } else {
  26.         echo "Sql Error";
  27.     }
  28.  
  29.     $finaljson = json_encode($dataarrayfinal);
  30.     echo $finaljson;
  31.  
  32.  
  33.  
  34. //$string = file_get_contents("sampleDailyData.json");
  35. //    $json = json_decode($string, true);
  36. //    echo $string;
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement