diff --git a/api_db.php b/api_db.php index ba172680..06b31e05 100644 --- a/api_db.php +++ b/api_db.php @@ -158,7 +158,11 @@ if (isset($_GET['topClients']) && $auth) { $limit = "WHERE timestamp <= :until"; } - $stmt = $db->prepare('SELECT client,count(client) FROM queries '.$limit.' GROUP by client order by count(client) desc limit 20'); + $dbquery= "Select CASE typeof(client) WHEN 'integer' THEN ("; + $dbquery .= " SELECT CASE TRIM(name) WHEN '' THEN c.ip ELSE c.name END name FROM client_by_id c WHERE c.id = q.client)"; + $dbquery .= " ELSE client END client, count(client) FROM query_storage q ".$limit." GROUP by client order by count(client) desc limit 20"; + + $stmt = $db->prepare($dbquery); $stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER); $stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER); $results = $stmt->execute();