First git commit
This commit is contained in:
30
public_html/games/scores.php
Normal file
30
public_html/games/scores.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../lib/bootstrap.php';
|
||||
$games = ['guess' => 'Guess the Number', 'quiz' => 'Quick Quiz',
|
||||
'ttt' => 'Noughts & Crosses', 'nim' => 'Nim'];
|
||||
$g = (string)($_GET['g'] ?? '');
|
||||
|
||||
page_start('High scores', ['back' => '/games.php']);
|
||||
|
||||
if (!isset($games[$g])) {
|
||||
p_para('Pick a game:');
|
||||
$links = [];
|
||||
foreach ($games as $k => $n) $links[] = ['/games/scores.php', $n, ['g' => $k]];
|
||||
p_links($links);
|
||||
} else {
|
||||
p_para($games[$g] . ' - top 10:');
|
||||
$s = db()->prepare("SELECT u.username, MAX(s.score) sc, COUNT(*) n
|
||||
FROM scores s JOIN users u ON u.id=s.user_id
|
||||
WHERE s.game=? GROUP BY s.user_id
|
||||
ORDER BY sc DESC LIMIT 10");
|
||||
$s->execute([$g]);
|
||||
$rows = $s->fetchAll();
|
||||
if (!$rows) p_para('No scores yet.');
|
||||
$i = 1;
|
||||
foreach ($rows as $r) {
|
||||
p_para($i++ . '. ' . $r['username'] . ' - ' . $r['sc'] . ' (' . $r['n'] . ' plays)');
|
||||
}
|
||||
p_links([['/games/scores.php', 'Other games']]);
|
||||
}
|
||||
p_links([['/games.php', 'Games'], ['/index.php', 'Home']]);
|
||||
page_end();
|
||||
Reference in New Issue
Block a user