remove records out of top 10

This commit is contained in:
2019-11-01 13:17:01 +01:00
parent 5de5f03b3c
commit f12ff135fa
8 changed files with 67 additions and 35 deletions

View File

@ -8,6 +8,14 @@
}
$query = $db->prepare('INSERT INTO `leaderboard` (`player`, `score`) VALUES (:player, :score);');
$query->execute(array("player" => strip_tags($_POST['player']), "score" => (int) $_POST['score']));
$RowsToDelete = $db->query('SELECT id FROM `leaderboard` ORDER BY score DESC LIMIT 10, 10;');
while($row = $RowsToDelete->fetch()) {
$id = $row['id'];
$db->query("DELETE FROM `leaderboard` WHERE id=" . $row['id'] . ";");
}
$row->closeCursor();
$db->close();
} else {
header($_SERVER["SERVER_PROTOCOL"] . " 405 Method Not Allowed", true, 405);
}