Fetch up to 20 clients and limit the list to 10 results in PHP

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2018-01-07 18:07:39 +01:00
parent 047329a4ae
commit 9cc8062c88
+5 -2
View File
@@ -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);