Advertisement
Guest User

Untitled

a guest
Jun 8th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.        
  3.         $server="xxx";
  4.         $user="xxxt";
  5.         $pass="xxx";
  6.         $db1="xxx";
  7.        
  8.        
  9.         $conn = mysqli_connect($server, $user, $pass, $db1);
  10.        
  11.         if ($conn->connect_error) {
  12.           die("Connection failed: " . $conn->connect_error);
  13.         }
  14.        
  15.         $query = "SELECT * FROM tempLog";
  16.        
  17.         $result = $conn->query($query);
  18.        
  19.         $jsonArray = array();
  20.        
  21.         if ($result->num_rows > 0) {
  22.          
  23.           while($row = $result->fetch_assoc()) {
  24.             $jsonArrayItem = array();
  25.             $jsonArrayItem['label'] = $row['czas'];
  26.             $jsonArrayItem['value'] = $row['temperature'];
  27.            
  28.             array_push($jsonArray, $jsonArrayItem);
  29.           }
  30.         }
  31.        
  32.         $conn->close();
  33.        
  34.        header('Content-type: application/json');
  35.        
  36.         echo json_encode($jsonArray);
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement