Advertisement
Guest User

Untitled

a guest
May 10th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. <?php
  2. // settings
  3. // host, user and password settings
  4. $host = "localhost";
  5. $user = "logger";
  6. $password = "password";
  7. $database = "temperatures";
  8.  
  9. //how many hours backwards do you want results to be shown in web page.
  10. $hours = 12;
  11.  
  12. // make connection to database
  13. $con = mysql_connect($host,$user,$password);
  14. // select db
  15. mysql_select_db($database,$con);
  16.  
  17. // sql command that selects all entires from current time and X hours backwards
  18. $sql="SELECT * FROM temperaturedata WHERE dateandtime >= (NOW() - INTERVAL $hours HOUR)";
  19.  
  20. //NOTE: If you want to show all entries from current date in web page uncomment line below by removing //
  21. //$sql="select * from temperaturedata where date(dateandtime) = curdate();";
  22.  
  23. // set query to variable
  24. $temperatures = mysql_query($sql);
  25.  
  26. // create content to web-pagge
  27. ?>
  28. <html>
  29. <head>
  30. <title>Temperatures</title>
  31. </head>
  32.  
  33. <body>
  34. </body>
  35.  
  36. <table width="600" border="1" cellpadding="1" cellspacing="1" align="center">
  37. <tr>
  38. <th>Date</th>
  39. <th>Sensor</th>
  40. <th>Temperature</th>
  41. <th>Humidity</th>
  42. <tr>
  43. <?php
  44. // loop all the results that were read from database and "draw" to web page
  45. while($temperature=mysql_fetch_assoc($temperatures)){
  46. echo "<tr>";
  47. echo "<td>".$temperature['dateandtime']."</td>";
  48. echo "<td>".$temperature['sensor']."</td>";
  49. echo "<td>".$temperature['temperature']."</td>";
  50. echo "<td>".$temperature['humidity']."</td>";
  51. echo "<tr>";
  52. }
  53. ?>
  54. </table>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement