leaderboard

This commit is contained in:
alvin 2025-12-11 11:24:05 +07:00
parent 4149a275fd
commit 6ba190ca85

23
load_leaderboard.php Normal file
View File

@ -0,0 +1,23 @@
<?php
require 'db.php';
header('Content-Type: application/json');
try {
$stmt = $pdo->query("
SELECT u.id AS user_id, u.username, s.wins, s.losses
FROM users u
LEFT JOIN users_stats s ON s.user_id = u.id
GROUP BY u.id
ORDER BY s.wins DESC, s.losses ASC
LIMIT 20
");
$rows = $stmt->fetchAll();
echo json_encode($rows);
} catch (Exception $e) {
echo json_encode([
"error" => $e->getMessage()
]);
}