Nächste Überarbeitung | Vorhergehende Überarbeitung |
arduino:php [2022/04/04 14:48] – angelegt khirling | arduino:php [2022/06/02 18:00] (aktuell) – khirling |
---|
Script zum Abspeichern der Messwerte | ====== Script zum Abspeichern der Messwerte ====== |
<code C> | |
| <sxh cpp; > |
<?php | <?php |
| |
| |
// GET Werte einlesen | // GET Werte einlesen |
if(isset($_GET['Wert1'])) {$wert1 = $_GET['Wert1']; | if(isset($_GET['Wert1'])) {$wert1 = $_GET['Wert1'];} else {$wert1 ="-------";} |
} else {$wert1 ="-------";} | if(isset($_GET['Wert2'])) {$wert2 = $_GET['Wert2'];} else {$wert2 ="-------";} |
| if(isset($_GET['Wert3'])) {$wert3 = $_GET['Wert3'];} else {$wert3 ="-------";} |
if(isset($_GET['Wert2'])) {$wert2 = $_GET['Wert2']; | if(isset($_GET['beschreibung'])) {$beschreibung = $_GET['beschreibung'];} else {$beschreibung ="-------";} |
} else {$wert2 ="-------";} | if(isset($_GET['info'])) {$info = $_GET['info'];} else {$info ="-------";} |
| |
if(isset($_GET['Wert3'])) {$wert3 = $_GET['Wert3']; | |
} else {$wert3 ="-------";} | |
| |
if(isset($_GET['beschreibung'])) {$beschreibung = $_GET['beschreibung']; | |
} else {$beschreibung ="-------";} | |
| |
if(isset($_GET['info'])) {$info = $_GET['info']; | |
} else {$info ="-------";} | |
| |
| |
// Eintrag in die Datenbank // | // Eintrag in die Datenbank // |
$sql ="INSERT INTO `1` (`id`, `wert1`, `wert2`, `wert3`, `beschreibung`, `info`, `zeit`) VALUES (NULL, '".$wert1."', '".$wert2."', '".$wert3."', '".$beschreibung."', '".$info."', CURRENT_TIMESTAMP);"; | $sql ="INSERT INTO `1` (`id`, `wert1`, `wert2`, `wert3`, `beschreibung`, `info`, `zeit`) |
| VALUES (NULL, '".$wert1."', '".$wert2."', '".$wert3."', '".$beschreibung."', '".$info."', CURRENT_TIMESTAMP);"; |
$pdo->query($sql); | $pdo->query($sql); |
?> | ?> |
<li> zeit: <?php echo $zeit; ?></li> | <li> zeit: <?php echo $zeit; ?></li> |
</ul> | </ul> |
| |
</body> | </body> |
</html> | </html> |
</code> | </sxh> |
| |
| ====== Script zum Anzeigen der Messwerte ====== |
| <sxh cpp; > |
| <?php |
| $pdo = new PDO('mysql:host=localhost;dbname=cu-luft', 'cu-Luft', 'Knk'); |
| /* Verbindungsdaten */ |
| // GET Werte einlesen |
| if(isset($_GET['messung'])) {$beschreibung = $_GET['messung'];} else {$beschreibung ="";} |
| ?> |
| <!DOCTYPE html> |
| <html lang="de"> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta http-equiv="expires" content="0"> |
| <meta http-equiv="refresh" content="30"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>Raumklima</title> |
| <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" /> |
| <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" /> |
| <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script> |
| <script type="text/javascript" src="js/bootstrap.min.js"></script> |
| <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script> |
| </head> |
| <body> |
| |
| |
| <!-- START --> |
| <div class="container"> |
| <h2>Messwerte:</h2> |
| |
| <!-- Beginn des Formulars --> |
| <div class="col-xs-12 col-sm-6 col-md-6"> |
| <form name="Messung" method="GET"> |
| <div class="form-group"> |
| <select class="form-control" id="messung" name ="messung"> |
| <?php |
| $sql ="SELECT DISTINCT `beschreibung` FROM `1` "; |
| foreach ($pdo->query($sql) as $row) { |
| echo"<option value=\"".$row['beschreibung']."\">".$row['beschreibung']."</option>"; |
| } |
| ?> |
| </select> |
| </div> |
| <button type="reset" class="btn col-4 btn-primary">Zurücksetzen</button> |
| <button type="submit" class="btn col-4 btn-primary">Absenden</button> |
| </form> |
| </div> |
| |
| <?php |
| if($beschreibung ==""){ |
| $sql= "SELECT * FROM `1` ORDER BY `id` DESC LIMIT 500"; |
| } |
| else { |
| $sql= "SELECT * FROM `1` where `beschreibung`='".$beschreibung."' ORDER BY `id` DESC LIMIT 500"; |
| } |
| |
| echo "<table class=\"table table-striped table-bordered\">"; |
| echo "<tr> <th>id</th><th>Wert 1 </th><th> Wert 2 </th><th> Wert 3 </th><th> Beschreibung </th><th> Info</th><th> Zeit</th></tr>"; |
| |
| foreach ($pdo->query($sql) as $row) { |
| echo "<tr><td>".$row['id']."</td><td>".$row['wert1']."</td><td>".$row['wert2']."</td><td>".$row['wert3']."</td><td>".$row['beschreibung']."</td><td>".$row['info']."</td><td>".$row['zeit']."</td></tr>"; |
| } |
| echo "</table>"; |
| ?> |
| |
| </div></body></html> |
| </sxh> |