-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_leaderboard.php
27 lines (22 loc) · 830 Bytes
/
get_leaderboard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
// Include database connection
include('database.php');
// Retrieve game type from request (default to aim_training)
$game = isset($_GET['game']) ? $_GET['game'] : 'aim_training';
$query = "SELECT username, score, accuracy FROM aim_training_scores ORDER BY score DESC LIMIT 10";
$result = $conn->query($query);
// Check if there are rows returned
if ($result->num_rows > 0) {
// Output the leaderboard data as JSON
$leaderboard_data = array();
while ($row = $result->fetch_assoc()) {
$leaderboard_data[] = $row;
}
echo json_encode(array('success' => true, 'leaderboard' => $leaderboard_data));
} else {
// No data found in the database
echo json_encode(array('success' => false, 'message' => 'No data found in the leaderboard'));
}
// Close the database connection
$conn->close();
?>