-
Notifications
You must be signed in to change notification settings - Fork 0
/
scores.php
107 lines (96 loc) · 4.24 KB
/
scores.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<html>
<head>
<!--Title in the tab-->
<title>Planet Lander</title>
<!--So the browser knows what character set to use (gets rid of annoying Javascript error)-->
<meta charset="UTF-8">
<!--This makes the icon appear in the tab-->
<link rel="icon" href="Resources/favicon.ico" type="image/ico">
<link href='https://fonts.googleapis.com/css?family=Molengo' rel='stylesheet' type='text/css'>
<!--CSS styling-->
<link rel="stylesheet" type="text/css" href="style.css">
<!--Page changing script-->
<script src="scores.js"></script>
</head>
<body>
<h1>All Planet Lander Scores</h1>
<button onclick="goBackS()" title="Click here to return back to the game">Back to Game</button>
<?php
//Connect to database
$servername = "127.0.0.1"; //localhost
$username = ""; //
$password = ""; //
$dbname = "planet_lander"; //Your database name you want to connect to
$port = ;
$count = 1;
//pn is the player's name
//ln is level number
//s is the score
//l is boolean whether the lander landed (true) or not (false)
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $port);
//Get information from mySQL
$sql = "SELECT id, Uname, Level, Time, Score, Landed FROM scores ORDER BY Score DESC, Landed DESC, Time DESC";
//Display information in HTML
$result = mysqli_query($conn, $sql);
echo "<br><br>";
echo "<table><tr id='title'><td>Rank</td><td>Username</td><td>Planet</td><td>Time</td><td>Score</td><td>Landed</td>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr id='scores'><td>" .$count++. "</td><td>" . $row["Uname"]. "</td><td>";
switch ($row["Level"]){
case 1;
echo "Mercury";
break;
case 2;
echo "Venus";
break;
case 3;
echo "Moon";
break;
case 4;
echo "Mars";
break;
case 4;
echo "Mars";
break;
case 5;
echo "Ganymede";
break;
case 6;
echo "Titan";
break;
case 7;
echo "Uranus";
break;
case 8;
echo "Neptune";
break;
case 9;
echo "Black Hole";
break;
default;
echo "?";
break;
}
echo"</td><td>" . $row["Time"]. "</td><td>" . $row["Score"]. "</td><td>";
if ($row["Landed"] == 0){
echo "No</td></tr>";
} else if ($row["Landed"] == 1){
echo "Yes</td><tr>";
} else if ($row["Landed"] == 2){
echo "Bonus</td><tr>";
} else {
echo "?</td><tr>";
}
}
} else {
echo "<p>No scores found :c</p>";
}
// close connection
mysqli_close($conn);
?>
</table>
</body>
</html>