less work on the database

This commit is contained in:
mcguirepr89
2022-02-07 14:44:06 -05:00
parent 207f05449c
commit 1dc7c8ae96
+17 -21
View File
@@ -1,4 +1,7 @@
<?php <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
header("refresh: 300;"); header("refresh: 300;");
$myDate = date('d-m-Y'); $myDate = date('d-m-Y');
$chart = "Combo-$myDate.png"; $chart = "Combo-$myDate.png";
@@ -12,33 +15,26 @@ if ($mysqli->connect_error) {
} }
// SQL query to select data from database // SQL query to select data from database
$sql0 = "SELECT * FROM detections"; $sql0 = "SELECT COUNT(*) AS 'Total' FROM detections";
$fulltable = $mysqli->query($sql0); $totalcount = $mysqli->query($sql0);
$totalcount = mysqli_num_rows($fulltable);
$sql1 = "SELECT Com_Name, Date, Time FROM detections $sql1 = "SELECT Com_Name, Date, Time FROM detections
ORDER BY Date DESC, Time DESC LIMIT 1"; ORDER BY Date DESC, Time DESC LIMIT 1";
$mostrecent = $mysqli->query($sql1); $mostrecent = $mysqli->query($sql1);
$sql2 = "SELECT * FROM detections $sql2 = "SELECT COUNT(*) AS 'Total' FROM detections
WHERE Date = CURDATE()"; WHERE Date = CURDATE()";
$todaystable = $mysqli->query($sql2); $todayscount = $mysqli->query($sql2);
$todayscount = mysqli_num_rows($todaystable);
$sql3 = "SELECT COUNT(*) AS 'Total' FROM detections
$sql3 = "SELECT * FROM detections
WHERE Date = CURDATE() WHERE Date = CURDATE()
AND Time >= DATE_SUB(NOW(),INTERVAL 1 HOUR)"; AND Time >= DATE_SUB(NOW(),INTERVAL 1 HOUR)";
$lasthourtable = $mysqli->query($sql3); $lasthourcount = $mysqli->query($sql3);
$lasthourcount = mysqli_num_rows($lasthourtable);
$sql4 = "SELECT Com_Name, Date, Time, MAX(Confidence) $sql4 = "SELECT COUNT(Com_Name) AS 'Total'
FROM detections FROM detections
WHERE Date = CURDATE() WHERE Date = CURDATE()";
GROUP BY Com_Name $speciescount = $mysqli->query($sql4);
ORDER BY MAX(Confidence) DESC";
$specieslist = $mysqli->query($sql4);
$speciescount = mysqli_num_rows($specieslist);
$mysqli->close(); $mysqli->close();
?> ?>
@@ -104,9 +100,9 @@ while($rows=$mostrecent ->fetch_assoc())
</tr> </tr>
<tr> <tr>
<th>Number of Detections</th> <th>Number of Detections</th>
<td><?php echo $totalcount;?></td> <td><?php while ($row = $totalcount->fetch_assoc()) { echo $row['Total']; };?></td>
<td><?php echo $todayscount;?></td> <td><?php while ($row = $todayscount->fetch_assoc()) { echo $row['Total']; };?></td>
<td><?php echo $lasthourcount;?></td> <td><?php while ($row = $lasthourcount->fetch_assoc()) { echo $row['Total']; };?></td>
</tr> </tr>
</table> </table>
</div> </div>
@@ -114,7 +110,7 @@ while($rows=$mostrecent ->fetch_assoc())
<table> <table>
<tr> <tr>
<th>Species Detected Today</th> <th>Species Detected Today</th>
<td><?php echo $speciescount;?></td> <td><?php while ($row = $speciescount->fetch_assoc()) { echo $row['Total']; };?></td>
</tr> </tr>
</table> </table>
</div> </div>
@@ -122,7 +118,7 @@ while($rows=$mostrecent ->fetch_assoc())
<h2>Today's Top 10 Species</h2> <h2>Today's Top 10 Species</h2>
<?php <?php
if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart)) { if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart)) {
echo "<img src=\"/Charts/$chart?nocache=$time()\" style=\"width: 100%;padding: 5px;margin-left: auto;margin-right: auto;display: block;\">"; echo "<img src=\"/Charts/$chart?nocache=time()\" style=\"width: 100%;padding: 5px;margin-left: auto;margin-right: auto;display: block;\">";
} else { } else {
echo "<p style=\"text-align:center;margin-left:-150px;\">No Detections For Today</p>"; echo "<p style=\"text-align:center;margin-left:-150px;\">No Detections For Today</p>";
} }