query("SHOW TABLES LIKE 'leaderboard_sudoku'"); if ($checkTable->rowCount() == 0) { $createSql = " CREATE TABLE leaderboard_sudoku ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50), difficulty VARCHAR(10), time_seconds INT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )"; $conn->exec($createSql); } } catch (PDOException $e) { // Fail silently or log, but attempting to continue might show empty leaderboard instead of crash } // Helper function to get top 10 by difficulty function getLeaderboard($conn, $difficulty) { $sql = " SELECT username, time_seconds, created_at FROM leaderboard_sudoku WHERE difficulty = :difficulty ORDER BY time_seconds ASC LIMIT 10 "; $stmt = $conn->prepare($sql); $stmt->execute(['difficulty' => $difficulty]); return $stmt->fetchAll(PDO::FETCH_ASSOC); } // Fetch data for each level $easyData = getLeaderboard($conn, 'easy'); $mediumData = getLeaderboard($conn, 'medium'); $hardData = getLeaderboard($conn, 'hard'); ?> Leaderboard Sudoku

🏆 Leaderboard

Level Mudah

Level Sedang

Level Sulit

Kembali ke Game Belum ada data.

"; return; } echo ""; echo ""; $rank = 1; foreach ($data as $row) { $timeStr = sprintf("%02d:%02d", floor($row['time_seconds'] / 60), $row['time_seconds'] % 60); $rankClass = ''; if ($rank == 1) $rankClass = 'rank-1'; elseif ($rank == 2) $rankClass = 'rank-2'; elseif ($rank == 3) $rankClass = 'rank-3'; echo ""; echo ""; echo ""; echo ""; echo ""; $rank++; } echo "
RankPlayerWaktu
#{$rank}" . htmlspecialchars($row['username']) . "{$timeStr}
"; } ?>