From 9cc8062c88ce6b562ccbcd6c05a83e4fde2e524f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 7 Jan 2018 18:07:39 +0100 Subject: [PATCH] Fetch up to 20 clients and limit the list to 10 results in PHP Signed-off-by: DL6ER --- api_db.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api_db.php b/api_db.php index df64176d..ff723d43 100644 --- a/api_db.php +++ b/api_db.php @@ -94,12 +94,13 @@ if (isset($_GET['topClients']) && $auth) { $limit = "WHERE timestamp <= ".$_GET["until"]; } - $results = $db->query('SELECT client,count(client) FROM queries '.$limit.' GROUP by client order by count(client) desc limit 10'); + $results = $db->query('SELECT client,count(client) FROM queries '.$limit.' GROUP by client order by count(client) desc limit 20'); $clients = array(); + $num = 0; if(!is_bool($results)) - while ($row = $results->fetchArray()) + while (($row = $results->fetchArray()) && $num < 10) { // Convert client to lower case $c = strtolower($row[0]); @@ -112,6 +113,8 @@ if (isset($_GET['topClients']) && $auth) { // Entry does not yet exist $clients[$c] = intval($row[1]); + // Increase number of clients + $num++; } } $result = array('top_sources' => $clients);