<?php
if (empty($_COOKIE['user'])) {
echo '<script>window.location.href = "../../"</script>';
}
include '../../mysqlHandler.php';
openConnection();
$user_id = 0;
if (!empty($_COOKIE['user'])) {
$result = executeQuery('select user_id from user where username ="' . $_COOKIE['user'] . '"');
}
// getting the user's id based on their cookie>username
if ($result) {
while ($row = mysql_fetch_array($result)) {
$user_id = $row['user_id'];
}
}
?>
<?php
include '../../t/headSectionUnclosed.php';
echo '</head> <body>';
include '../../t/userBar.php';
?>
<h1>
High Scores List
</h1>
<hr>
<h2>
Your Best Five Scores
</h2>
<?php
$scores = executeQuery('select score from user_score where user_id = ' . $user_id . ' order by score desc limit 0, 5');
$count = 0;
if (mysql_num_rows($scores) > 0) {
echo '<table id="highscores-table">';
echo '<tr>';
echo '<th> </th>';
echo '<th>Score</th>';
echo '</tr>';
if ($scores) {
while ($row = mysql_fetch_array($scores)) {
echo '<tr>';
echo '<td>';
echo++$count;
echo '</td><td>';
echo $row['score'];
echo '</td>';
echo '</tr>';
}
}
echo '</table>';
} else {
echo "<em>You don't have any high scores yet.</em>";
}
echo '<br><br>';
echo '<a href="../" id="button-link">Improve your scores →</a>';
echo '<br><br>';
?>
<hr>
<h2>
Global Top 10
</h2>
<table id="highscores-table">
<tr>
<th>Rank</th>
<th>User</th>
<th>Score</th>
</tr>
<?php
$global_high_scores = executeQuery('select u.username, s.score from user u, user_score s where u.user_id = s.user_id order by s.score desc limit 0, 10');
if ($global_high_scores) {
$ranking = 0;
while ($row = mysql_fetch_array($global_high_scores)) {
$ranking++;
echo '<tr>';
echo '<td>';
echo $ranking;
echo '</td>';
echo '<td>';
echo $row['username'];
echo '</td>';
echo '<td>';
echo $row['score'];
echo '</td>';
echo '</tr>';
}
}
?>
</table>
<br><br>
<a href="../" id="button-link">Improve your scores →</a>
<br><br>
<br><br><br><br>
</body></html>