From ad45d764b12cb534a93269bf15b56db5dc278c25 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 13 Apr 2022 15:56:11 -0300 Subject: [PATCH] Return empty array if there is no data Signed-off-by: RD WebDesign --- api_db.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/api_db.php b/api_db.php index 511f55d0..a10212a7 100644 --- a/api_db.php +++ b/api_db.php @@ -87,10 +87,11 @@ if (isset($_GET['getAllQueries']) && $auth) $stmt->bindValue(":from", intval($from), SQLITE3_INTEGER); $stmt->bindValue(":until", intval($until), SQLITE3_INTEGER); $results = $stmt->execute(); - if (!is_bool($results)) { - // Start the JSON string - echo '{"data":['; + // Start the JSON string + echo '{"data":['; + + if (!is_bool($results)) { $first = true; while ($row = $results->fetchArray()) { // Insert a comma before the next record (except on the first one) @@ -109,10 +110,11 @@ if (isset($_GET['getAllQueries']) && $auth) // array: time type domain client status upstream destination echo json_encode([$row[0], $query_type, $domain, $row[3], $row[4], $destination]); } - - // Finish the JSON string - echo ']}'; } + + // Finish the JSON string + echo ']}'; + // exit at the end exit(); }