2025-12-03 12:21:15 +07:00

78 lines
1.7 KiB
PHP

<?php
session_start();
require_once "koneksi.php";
if (isset($_SESSION['username'])) {
$nama = $_SESSION['username'];
} else {
$nama = "";
}
$score = 0;
if (!empty($nama)) {
$getScore = "SELECT score FROM users WHERE username = '$nama'";
$resultMe = mysqli_query($koneksi, $getScore);
if ($resultMe && mysqli_num_rows($resultMe) > 0) {
$row = mysqli_fetch_assoc($resultMe);
$score = $row['score'];
}
}
$sql = "SELECT username, score FROM users ORDER BY score DESC LIMIT 10";
$result = mysqli_query($koneksi, $sql);
$leaderboard = [];
if($result) {
$leaderboard = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leaderboard</title>
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
</head>
<body>
<table>
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php
$peringkat = 1;
if (!empty($leaderboard)) {
foreach ($leaderboard as $pemain):
?>
<tr>
<td><?php echo $peringkat; ?></td>
<td><?php echo htmlspecialchars($pemain['username']); ?></td>
<td><?php echo $pemain['score']; ?> PTS</td>
</tr>
<?php
$peringkat++;
endforeach;
} else {
echo '<tr><td colspan="3" style="text-align: center;">Belum ada Pemain</td></tr>';
}
?>
</tbody>
</table>
</body>
</html>