Leaderboard Fix
This commit is contained in:
parent
9dae58f29d
commit
d27b2bf3f9
16
Sudoku.php
16
Sudoku.php
@ -793,14 +793,18 @@ if (!isset($_SESSION['username'])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveScore() {
|
function saveScore() {
|
||||||
fetch("save_score.php", {
|
fetch("/kelompok03-codeplay-Angelica-Rinaldo-Farrel/save_score.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
headers: {
|
||||||
body: `difficulty=${currentDifficulty}&time=${secondsElapsed}`
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
});
|
},
|
||||||
|
body: 'difficulty=${currentDifficulty}&time=${secondsElapsed}'
|
||||||
|
})
|
||||||
|
.then(res => res.text())
|
||||||
|
.then(data => console.log("SAVE SCORE:", data))
|
||||||
|
.catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -1,11 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'db.php';
|
require_once 'db.php';
|
||||||
|
|
||||||
// TES KONEKSI
|
|
||||||
if (!$conn) {
|
|
||||||
die("DB connection failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT username, difficulty, time_seconds
|
SELECT username, difficulty, time_seconds
|
||||||
FROM leaderboard_sudoku
|
FROM leaderboard_sudoku
|
||||||
@ -13,7 +8,8 @@ $sql = "
|
|||||||
LIMIT 10
|
LIMIT 10
|
||||||
";
|
";
|
||||||
|
|
||||||
$result = $conn->query($sql);
|
$stmt = $conn->query($sql);
|
||||||
|
$data = $stmt->fetchAll();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@ -48,8 +44,8 @@ $result = $conn->query($sql);
|
|||||||
<th>Time</th>
|
<th>Time</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php if ($result && $result->num_rows > 0): ?>
|
<?php if (count($data) > 0): ?>
|
||||||
<?php while ($row = $result->fetch_assoc()): ?>
|
<?php foreach ($data as $row): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= htmlspecialchars($row['username']) ?></td>
|
<td><?= htmlspecialchars($row['username']) ?></td>
|
||||||
<td><?= strtoupper($row['difficulty']) ?></td>
|
<td><?= strtoupper($row['difficulty']) ?></td>
|
||||||
@ -61,14 +57,11 @@ $result = $conn->query($sql);
|
|||||||
) ?>
|
) ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endwhile; ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">Belum ada data</td>
|
<td colspan="3">Belum ada data</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php $conn->close(); ?>
|
|
||||||
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
session_start();
|
|
||||||
require "koneksi.php"; // sesuaikan dengan file koneksi DB kamu
|
|
||||||
|
|
||||||
if (!isset($_SESSION['username'])) exit;
|
|
||||||
|
|
||||||
$username = $_SESSION['username'];
|
|
||||||
$difficulty = $_POST['difficulty'];
|
|
||||||
$time = intval($_POST['time']);
|
|
||||||
|
|
||||||
$stmt = $conn->prepare("INSERT INTO leaderboard_sudoku (username, difficulty, time_seconds) VALUES (?, ?, ?)");
|
|
||||||
$stmt->bind_param("ssi", $username, $difficulty, $time);
|
|
||||||
$stmt->execute();
|
|
||||||
@ -1,84 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
|
session_start();
|
||||||
require_once 'db.php';
|
require_once 'db.php';
|
||||||
|
|
||||||
$sql = "
|
if (!isset($_SESSION['username'])) {
|
||||||
SELECT username, difficulty, time_seconds
|
echo "NO_SESSION";
|
||||||
FROM leaderboard_sudoku
|
exit;
|
||||||
ORDER BY difficulty,
|
}
|
||||||
time_seconds ASC
|
|
||||||
";
|
|
||||||
|
|
||||||
$result = $conn->query($sql);
|
if (!isset($_POST['difficulty'], $_POST['time'])) {
|
||||||
?>
|
echo "NO_POST";
|
||||||
<!DOCTYPE html>
|
exit;
|
||||||
<html>
|
}
|
||||||
<head>
|
|
||||||
<title>Leaderboard Sudoku</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: Arial;
|
|
||||||
background: #1e1e1e;
|
|
||||||
color: #fff;
|
|
||||||
padding: 40px;
|
|
||||||
}
|
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
width: 600px;
|
|
||||||
margin: auto;
|
|
||||||
background: #2b2b2b;
|
|
||||||
}
|
|
||||||
th, td {
|
|
||||||
padding: 12px;
|
|
||||||
text-align: center;
|
|
||||||
border-bottom: 1px solid #444;
|
|
||||||
}
|
|
||||||
th {
|
|
||||||
background: #3b3b3b;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
text-align: center;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
.back {
|
|
||||||
display: block;
|
|
||||||
margin: 30px auto;
|
|
||||||
width: 200px;
|
|
||||||
text-align: center;
|
|
||||||
padding: 10px;
|
|
||||||
background: #4caf50;
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h1>🏆 Leaderboard Sudoku</h1>
|
$username ='testuser';
|
||||||
|
$difficulty = $_POST['difficulty'];
|
||||||
|
$time = (int) $_POST['time'];
|
||||||
|
|
||||||
<table>
|
$sql = "INSERT INTO leaderboard_sudoku
|
||||||
<tr>
|
(username, difficulty, time_seconds)
|
||||||
<th>Username</th>
|
VALUES (:username, :difficulty, :time)";
|
||||||
<th>Difficulty</th>
|
|
||||||
<th>Time (mm:ss)</th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<?php while ($row = $result->fetch(PDO::FETCH_ASSOC)): ?>
|
$stmt = $conn->prepare($sql);
|
||||||
<tr>
|
$stmt->execute([
|
||||||
<td><?= htmlspecialchars($row['username']) ?></td>
|
':username' => $username,
|
||||||
<td><?= strtoupper($row['difficulty']) ?></td>
|
':difficulty' => $difficulty,
|
||||||
<td>
|
':time' => $time
|
||||||
<?= sprintf("%02d:%02d",
|
]);
|
||||||
floor($row['time_seconds'] / 60),
|
|
||||||
$row['time_seconds'] % 60
|
|
||||||
) ?>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<?php endwhile; ?>
|
|
||||||
|
|
||||||
</table>
|
echo "SUCCESS";
|
||||||
|
|
||||||
<a href="index.php" class="back">⬅ Kembali</a>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user