<?php
header('Content-Type: application/json');
require 'Koneksi.php';

$query = "SELECT username, score FROM leaderboard ORDER BY score DESC LIMIT 10";
$result = $conn->query($query);

$leaderboard = [];

if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $leaderboard[] = $row;
    }
}

// Kirim data ke frontend dalam bentuk JSON
echo json_encode([
    "status" => "success",
    "leaderboard" => $leaderboard
]);

$conn->close();
?>