A live bird collage card for your Home Assistant dashboard.
less work on the db
mcguirepr89db69fcc55167
diff --git a/scripts/viewdb.php b/scripts/viewdb.phpindex 4e247aaa..cf6bafa2 100644--- a/scripts/viewdb.php+++ b/scripts/viewdb.php@@ -1,4 +1,8 @@<?php+ini_set('display_errors', 1);+ini_set('display_startup_errors', 1);+error_reporting(E_ALL);+header("refresh: 30;");$mysqli = mysqli_connect();$mysqli->select_db('birds');@@ -10,10 +14,9 @@ if ($mysqli->connect_error) {}// SQL query to select data from database-$sql = "SELECT * FROM detections+$sql = "SELECT COUNT(*) AS 'Total' FROM detectionsORDER BY Date DESC, Time DESC";-$fulltable = $mysqli->query($sql);-$totalcount=mysqli_num_rows($fulltable);+$totalcount = $mysqli->query($sql);$sql1 = "SELECT Date, Time, Sci_Name, Com_Name, MAX(Confidence)FROM detections@@ -22,26 +25,25 @@ $sql1 = "SELECT Date, Time, Sci_Name, Com_Name, MAX(Confidence)ORDER BY Time DESC";$mosttable = $mysqli->query($sql1);-$sql2 = "SELECT * FROM detections+$sql2 = "SELECT COUNT(*) AS 'Total' FROM detectionsWHERE Date = CURDATE()";-$todaystable = $mysqli->query($sql2);-$todayscount=mysqli_num_rows($todaystable);+$todayscount = $mysqli->query($sql2);-$sql3 = "SELECT * FROM detections+$sql3 = "SELECT COUNT(*) AS 'Total' FROM detectionsWHERE Date = CURDATE()AND Time >= DATE_SUB(NOW(),INTERVAL 1 HOUR)";-$lasthourtable = $mysqli->query($sql3);-$lasthourcount=mysqli_num_rows($lasthourtable);+$lasthourcount = $mysqli->query($sql3);-$sql4 = "SELECT Com_Name, Date, Time, MAX(Confidence)- FROM detections- GROUP BY Com_Name+$sql4 = "SELECT Com_Name, Date, Time, MAX(Confidence)+ FROM detections+ WHERE Date = CURDATE()+ GROUP BY Com_NameORDER BY MAX(Confidence) DESC";$specieslist = $mysqli->query($sql4);-$speciescount=mysqli_num_rows($specieslist);+$speciescount = mysqli_num_rows($specieslist);$sql5 = "SELECT Com_Name,COUNT(*)- AS Total+ AS 'Total'FROM detectionsGROUP BY Com_NameORDER BY Total DESC";@@ -73,9 +75,9 @@ $mysqli->close();<th>Number of Unique Species</th></tr><tr>- <td><?php echo $totalcount;?></td>- <td><?php echo $todayscount;?></td>- <td><?php echo $lasthourcount;?></td>+ <td><?php while ($row = $totalcount->fetch_assoc()) { echo $row['Total']; };?></td>+ <td><?php while ($row = $todayscount->fetch_assoc()) { echo $row['Total']; };?></td>+ <td><?php while ($row = $lasthourcount->fetch_assoc()) { echo $row['Total']; };?></td><td><?php echo $speciescount;?></td></tr></table>