forked from PeterHart23/Snake-Game-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.php
50 lines (43 loc) · 1.27 KB
/
load.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
// Code by Jacob Calfee & Peter Hart //
$servername = "localhost:3308";
$username = "root";
$password = "";
$dbname = "snake_scores";
$conn = new mysqli($servername, $username, $password, $dbname) or die ("Connect failed: %d\n" . $conn->error);
// Generate base query //
$sql = "SELECT * FROM `TABLE 1` ORDER BY `TABLE 1`.`Score` DESC ";
$result = $conn->query($sql);
if (!$result) {
trigger_error('Invalid query: ' . $conn->error);
}
$place = 1;
// Generate the table to be sent to index.html //
if ($result->num_rows > 0) {
// output data of each row
$str = "<table>";
$str .= "<tr>";
$str .= "<th></th>";
$str .= "<th>HIGH SCORES</th>";
$str .= "<th></th>";
$str .= "</tr>";
$str .= "<tr>";
$str .= "<th>Place</th>";
$str .= "<th>Username</th>";
$str .= "<th>Score</th>";
$str .= "</tr>";
while($row = $result->fetch_assoc()) {
$str .= "<tr>";
$str .= "<td>" . $place . "</td>";
$str .= "<td>" . $row['Username'] . "</td>";
$str .= "<td>" . $row['Score'] . "</td>";
$str .= "</tr>";
$place += 1;
}
$str .= "</table>";
echo $str;
} else {
echo "0 results";
}
$conn->close();
?>