-
Notifications
You must be signed in to change notification settings - Fork 0
/
highscores.php
136 lines (103 loc) · 3.63 KB
/
highscores.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!-- Connecting to the Database -->
<?php include 'includes/dbc.php';?>
<?php session_start();
if(!isset($_GET['lessonID'])) {
$lessonID = 0;
} else {$lessonID = $_GET['lessonID'];}
function getLessonName($quizID) {
$dbc = mysqli_connect("localhost", "root", 'admin', "srs");
// Retrieveing the lesson Name for Heading
$getLessonNameQuery = "CALL `GetSubjectName`($quizID)";
$getLessonNameResult = mysqli_query($dbc, $getLessonNameQuery);
$getLessonNameRecord = mysqli_fetch_assoc($getLessonNameResult);
$lessonName = $getLessonNameRecord['subjectName'];
return $lessonName;
}
if ($lessonID == 0) {$lessonName = "All Highscores";}
else {$lessonName = getLessonName($lessonID);}
?>
<!-- Start of HTML Page -->
<!DOCTYPE html>
<html lang="en">
<!-- Constants.php should incude: Site title & other constants -->
<?php include 'includes/constants.php'; ?>
<head>
<title><?php echo $title ?></title>
<?php include 'includes/head.php'; ?>
</head>
<body>
<div id="body-wrapper">
<?php include 'includes/header.php'; ?>
<div class="title-page">
<div id="title-container">
<h1 class="title-text">Highscores</h1>
<h2 class="lesson-name"><?php echo $lessonName ?></h2>
</div>
</div>
<div class="lesson-btns-wrapper">
<div class="lesson-btns container">
<?php
// Setting up the query
$dbc = mysqli_connect("localhost", "root", 'admin', "srs");
$query = 'CALL GetSubjects()';
$allLessons = mysqli_query($dbc, $query);
// Itterating through the
foreach ($allLessons as $lesson) {
$lessonNameClass = str_replace(" ", "", $lesson['subjectName']);
$lessonName = $lesson['subjectName'];
$lessonID = $lesson['subjectID'];
echo "<a class='lesson-btns' href='highscores.php?lessonID=$lessonID'>$lessonName</a>";
}
?>
</div>
</div>
<div class="highscore-table-wrapper">
<div class="highscore-table-container">
<table class="highscore-table">
<tr class="table-titles">
<th>Initials</th>
<th>Highscore</th>
</tr>
</table>
<?php
if (isset($_GET["lessonID"]) && $_GET["lessonID"] >= 1) {
// Setting vairables
$lessonID = $_GET["lessonID"]; // creating array out of get string
// Setting up the query
$dbc = mysqli_connect("localhost", "root", 'admin', "srs");
$query = "CALL GetHighscore($lessonID)";
$hsResult = mysqli_query($dbc, $query);
// TODO: Itterate through the answer states
// Itterating through questions into table
while($highscores = mysqli_fetch_assoc($hsResult)){
// Spacer Row
echo "<div class='spacer'>";
echo "<div class='spacer'></div>";
echo "</div>";
// Data Row
echo "<div class='row'>";
echo "<div class='initials'>" . $highscores['initials'] . "</div>";
echo "<div class='highscore'>" . $highscores['highscore'] . "</div>";
echo "</div>";
}
}
else {
echo "<div class='spacer'>";
echo "<div class='spacer'></div>";
echo "</div>";
// Data Row
echo "<div class='row'>";
echo "<div class='initials' style='width:100%'>Select a lesson above</div>";
echo "</div>";
}
?>
</div>
</div>
</div>
<?php $_SESSION['answerList'] = []; ?>
<footer> <!-- Nav bar inspired by https://www.youtube.com/watch?v=PwWHL3RyQgk -->
<?php include 'includes/footer.php'; ?>
</footer>
<?php include 'includes/scripts.php'; ?>
</body>
</html>