T201704101414
This commit is contained in:
@@ -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
|
||||
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) {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user