From cc7ba892094c2e39405e431fc4531d82e244ba73 Mon Sep 17 00:00:00 2001 From: 5803025031 Date: Thu, 11 Dec 2025 11:08:16 -0500 Subject: [PATCH] Upload files to "/" --- index.php | 4 +- leaderboard.php | 145 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 109 insertions(+), 40 deletions(-) diff --git a/index.php b/index.php index 44f8f31..256dc0d 100644 --- a/index.php +++ b/index.php @@ -3,8 +3,8 @@ session_start(); $conn = new mysqli("localhost","root","","breakout_db"); if($conn->connect_error){ die("DB Error"); } -$isLoggedIn = isset($_SESSION['user']); // SUDAH DIPERBAIKI -$username = $isLoggedIn ? htmlspecialchars($_SESSION['user']) : null; // SUDAH DIPERBAIKI +$isLoggedIn = isset($_SESSION['user']); +$username = $isLoggedIn ? htmlspecialchars($_SESSION['user']) : null; ?> diff --git a/leaderboard.php b/leaderboard.php index ae8faf0..982f10d 100644 --- a/leaderboard.php +++ b/leaderboard.php @@ -1,57 +1,126 @@ query("SELECT username, highscore FROM users ORDER BY highscore DESC LIMIT 10"); +$conn = new mysqli("localhost", "root", "", "breakout_db"); +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} -$isLoggedIn = isset($_SESSION['user']); // SUDAH DIPERBAIKI -$username = $isLoggedIn ? htmlspecialchars($_SESSION['user']) : null; // SUDAH DIPERBAIKI +$lb_easy = $conn->query("SELECT username, highscore_easy FROM users WHERE highscore_easy > 0 ORDER BY highscore_easy DESC LIMIT 10"); + +$lb_medium = $conn->query("SELECT username, highscore_medium FROM users WHERE highscore_medium > 0 ORDER BY highscore_medium DESC LIMIT 10"); + +$lb_hard = $conn->query("SELECT username, highscore_hard FROM users WHERE highscore_hard > 0 ORDER BY highscore_hard DESC LIMIT 10"); + +$isLoggedIn = isset($_SESSION['user']); ?> - -Leaderboard + + + Leaderboard - Breakout Game - - - - + + + -

Leaderboard

+

Hall of Fame

-< -
- - - - - - - - - fetch_assoc()) { ?> - - - - - - -
UsernameHighscore
-
+
+ +
+

Easy Level

+ + + + + + + + + num_rows > 0) { + while($r = $lb_easy->fetch_assoc()) { + echo " + + + "; + } + } else { + echo ""; + } + ?> + +
UsernameScore
" . htmlspecialchars($r['username']) . "" . htmlspecialchars($r['highscore_easy']) . "
No records yet
+
-⬅ Back +
+

Medium Level

+ + + + + + + + + num_rows > 0) { + while($r = $lb_medium->fetch_assoc()) { + echo " + + + "; + } + } else { + echo ""; + } + ?> + +
UsernameScore
" . htmlspecialchars($r['username']) . "" . htmlspecialchars($r['highscore_medium']) . "
No records yet
+
+ +
+

Hard Level

+ + + + + + + + + num_rows > 0) { + while($r = $lb_hard->fetch_assoc()) { + echo " + + + "; + } + } else { + echo ""; + } + ?> + +
UsernameScore
" . htmlspecialchars($r['username']) . "" . htmlspecialchars($r['highscore_hard']) . "
No records yet
+
+ +
+ ⬅ Back to Game \ No newline at end of file