Advertisement
wofus

Abfrage DB max. Wert

Sep 30th, 2022 (edited)
1,160
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 1 0
  1. <?php
  2.  
  3. ini_set('display_errors', TRUE);
  4. ini_set('display_startup_errors', TRUE);
  5. error_reporting(E_ALL ^ E_NOTICE);
  6.  
  7. function maxdaytemp(){
  8.     $mysqlhost = "localhost";
  9.     $mysqluser = "andreas";
  10.     $mysqlpwd = "";
  11.     $mysqldb = "wetter";
  12.  
  13.     $connect = new mysqli($mysqlhost, $mysqluser, $mysqlpwd, $mysqldb) or die ("Could not connect to DB!");
  14.    
  15.     if (!$connect) {
  16.       die("Connection failed: " . mysqli_connect_error());
  17.     }  
  18.    
  19.     $sql = "SELECT MAX(Temperatur_Balkon) AS maxtemp FROM `temperaturverlauf` ORDER BY Zeit DESC LIMIT 288";
  20.     $result = mysqli_query($connect, $sql);
  21.    
  22.     $row = mysqli_fetch_array($result);
  23.     echo $row["maxtemp"];
  24. }
  25.  
  26. ?>
  27.  
  28. <!DOCTYPE html>
  29. <html lang="de" >
  30. <head>
  31.     <meta charset="UTF-8">
  32.     <title>Temperaturverlauf</title>
  33.     <link rel="stylesheet" href="style.css">
  34. </head>
  35. <body>
  36.  
  37. <div id="maxtemperatur" ><p>Höchste Temperatur der letzten 24 Stunden: <b><?php maxdaytemp() ?></b></p><div>
  38.  
  39. <div id="mintemperatur" ><p>Niedrigste Temperatur der letzten 24 Stunden: <b></b></p><div>
  40.  
  41. </div>
  42.  
  43. </body>
  44. </html>
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement