Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dataarrayfinal= array();
- $servername = "localhost";
- $username = "root";
- $password = "admin";
- $dbname = "wetterstation";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- $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";
- $result_temp = $conn->query($sql_temp_sensor);
- // ----------------- FETCH Temp Data -----------------------------
- if ($result_temp->num_rows > 0) {
- // output data of each row
- while($row = $result_temp->fetch_assoc()) {
- $temperature = $row["temperature"];
- $humidity = $row["humidity"];
- $dataarray = array('temperature' => $temeparture, 'humidity' => $humidity);
- array_push($dataarrayfinal, $dataarray);
- }
- } else {
- echo "Sql Error";
- }
- $finaljson = json_encode($dataarrayfinal);
- echo $finaljson;
- //$string = file_get_contents("sampleDailyData.json");
- // $json = json_decode($string, true);
- // echo $string;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement