From f203fde9f4ac97be0f680352b4798fd714e08594 Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Fri, 22 Apr 2022 10:45:46 -0400 Subject: [PATCH] Sort recordings by ABC, or occurrences --- scripts/play.php | 59 +++++++++++++++++++++++++++++++-- scripts/stats.php | 84 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 130 insertions(+), 13 deletions(-) diff --git a/scripts/play.php b/scripts/play.php index bc16fd1..d24cd39 100644 --- a/scripts/play.php +++ b/scripts/play.php @@ -33,7 +33,11 @@ if(isset($_GET['byfilename'])){ $date = $_GET['date']; session_start(); $_SESSION['date'] = $date; - $statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name"); + if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") { + $statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" GROUP BY Com_Name ORDER BY COUNT(*) DESC"); + } else { + $statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name"); + } if($statement == False){ echo "Database is busy"; header("refresh: 0;"); @@ -43,7 +47,11 @@ if(isset($_GET['byfilename'])){ #By Species } elseif(isset($_GET['byspecies'])) { - $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name'); + if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") { + $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC'); + } else { + $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name ASC'); + } session_start(); if($statement == False){ echo "Database is busy"; @@ -87,6 +95,53 @@ if(isset($_GET['byfilename'])){ if(!isset($_GET['species']) && !isset($_GET['filename'])){ ?>