42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: leanderschmedemann
|
|
* Date: 10.04.17
|
|
* Time: 13:24
|
|
*/
|
|
|
|
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();
|
|
|
|
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);
|
|
print_r($response); |