-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.php
113 lines (84 loc) · 2.93 KB
/
results.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
<!-- Connecting to the Database -->
<?php include 'includes/dbc.php';?>
<?php session_start();
// echo $_POST['initials']; // TESTING:
// echo $_GET['lessonID']; // TESTING:
// var_dump($_SESSION['answerList']); // TESTING:
if(isset($_POST['initials'])){
AddHighscore();
}
function AddHighscore() {
echo "<script> console.log('addHighscore Running'); </script>"; // TESTING:
$dbc = mysqli_connect("localhost", "root", 'admin', "srs");
$lessonID = $_GET['lessonID']; // passed through the GET
$initials = $_POST['initials']; // passed when the user submits their initials
$score = $_SESSION['score']; //
$addHighscoreQuery = "CALL `AddHighscore`($score, $lessonID, '$initials');";
$addHighscore = mysqli_query($dbc, $addHighscoreQuery);
// Redirecting user to the highscore page after submitting score
echo "<script>
var src = 'highscores.php?lessonID=$lessonID';
window.location.replace(src);
</script>";
}
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 (isset($_GET['lessonID'])) {
$lessonName = getLessonName($_GET['lessonID']);
} else {
$lessonName = "";
}
?>
<!-- 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';
// Checking id the session vairables are loaded:
if ($_SESSION['questions'] == [] || $_SESSION['answerList'] == []) {
$_SESSION['score'] = "N/A";
$lessonName = "";
}
?>
<div class="title-page">
<div id="title-container">
<h1 class="title-text">Results</h1>
<h2 class="lesson-name"><?php echo $lessonName ?></h2>
<pre class="score-text"><?php echo "Score: " . $_SESSION['score'] ?></pre>
</div>
</div>
<!-- Copy and paste from results table -->
<?php
if ($_SESSION['questions'] == [] || $_SESSION['answerList'] == []) {
include 'includes/no-results.php';
echo '<script>console.log("No Results");</script>'; // TESTING:
} else {
include 'includes/results-table.php';
}
?>
</div>
<?php
// Resetting vairbales`
$_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>