From 0e21b005846a4d2a26688783cc7c993eed23a67f Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Fri, 15 Apr 2022 17:07:44 -0400 Subject: [PATCH] JS implementation on Today's Detections Today's Detections "show 40 more button" is now handled through javascript rather than a page refresh. 1) Looks cleaner 2) Only loads the data we need, reducing DB calls and bandwidth --- scripts/todays_detections.php | 123 +++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 53 deletions(-) diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php index dd748d2..e50a2e7 100644 --- a/scripts/todays_detections.php +++ b/scripts/todays_detections.php @@ -3,27 +3,12 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); -if(isset($_GET['display_limit'])) { - if(is_numeric($_GET['display_limit'])) { - $display_limit = $_GET['display_limit'] + 40; - } -} else { - $display_limit = 40; -} - $db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); if($db == False){ echo "Database is busy"; header("refresh: 0;"); } -$statement0 = $db->prepare('SELECT Time, Com_Name, Sci_Name, Confidence, File_Name FROM detections WHERE Date == Date(\'now\', \'localtime\') ORDER BY Time DESC LIMIT '.$display_limit.''); -if($statement0 == False){ - echo "Database is busy"; - header("refresh: 0;"); -} -$result0 = $statement0->execute(); - $statement1 = $db->prepare('SELECT COUNT(*) FROM detections'); if($statement1 == False){ echo "Database is busy"; @@ -71,6 +56,48 @@ if($statement6 == False){ } $result6 = $statement6->execute(); $totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC); + +if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isset($_GET['display_limit']) && is_numeric($_GET['display_limit']) ) { + $statement0 = $db->prepare('SELECT Time, Com_Name, Sci_Name, Confidence, File_Name FROM detections WHERE Date == Date(\'now\', \'localtime\') ORDER BY Time DESC LIMIT '.(intval($_GET['display_limit'])-40).',40'); + if($statement0 == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + $result0 = $statement0->execute(); + + ?>
| Total | -Today | -Last Hour | -Unique Species Total | -Unique Species Today | +Total | +Today | +Last Hour | +Unique Species Total | +Unique Species Today |
|---|---|---|---|---|---|---|---|---|---|
| @@ -109,38 +136,28 @@ $totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC); |