From f7e2a85e43ede6b7a4d5ef03acaea346ed5ed892 Mon Sep 17 00:00:00 2001 From: Leander Date: Mon, 10 Apr 2017 14:14:44 +0200 Subject: [PATCH] T201704101414 --- allhighscores.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/allhighscores.php b/allhighscores.php index 7406696..411392a 100644 --- a/allhighscores.php +++ b/allhighscores.php @@ -9,17 +9,33 @@ require_once('includes.inc.php'); $data = array(); $error = 0; +$cid = isset($_GET['category']) ? $_GET['category'] : -1; $limit = isset($_GET['limit']) ? $_GET['limit'] : 10; $offset = isset($_GET['offset']) ? $_GET['offset'] : 0; $db = new Database(); -$overview = $db->query('SELECT "name", "highscore" FROM "Users" ORDER BY "highscore" DESC - LIMIT $1 OFFSET $2', array($limit, $offset))['data']; -foreach($overview as $row) { - $name = $row['name']; - $score = $row['highscore']; - $place = $db->query('SELECT COUNT(*) FROM "Users" WHERE "highscore" > $1', array($score))['data'][0]['count'] + 1; - $data[] = array('place' => $place, 'name' => $name, 'score' => $score); +if($category == -1) { + $overview = $db->query('SELECT "name", "highscore" FROM "Users" ORDER BY "highscore" DESC + LIMIT $1 OFFSET $2', array($limit, $offset))['data']; + foreach ($overview as $row) { + $name = $row['name']; + $score = $row['highscore']; + $place = $db->query('SELECT COUNT(*) FROM "Users" WHERE "highscore" > $1', array($score))['data'][0]['count'] + 1; + $data[] = array('place' => $place, 'name' => $name, 'score' => $score); + } +} else { + $overview = $db->query('SELECT u."name", h."score" + FROM "Users" u JOIN "Highscores" h ON u."ID" = h."Users_ID" + WHERE h."Categories_ID" = $1 + ORDER BY h."score" DESC + LIMIT $2 OFFSET $3', array($cid, $limit, $offset))['data']; + foreach ($overview as $row) { + $name = $row['name']; + $score = $row['score']; + $place = $db->query('SELECT COUNT(*) FROM "Highscores" WHERE "score" > $1 AND "Categories_ID" = $2', + array($score, $cid))['data'][0]['count'] + 1; + $data[] = array('place' => $place, 'name' => $name, 'score' => $score); + } } $response = Database::create_response($data, $error);