Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projects/anton-quiz/admin/
create_answer.php
create_question.php
create_quiz.php
dashboard.php
edit_quiz.php
show_results.php
view_details.php
view_details.php
106 lines UTF-8 Windows (CRLF)
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
<?php
session_start();
// Kontroll: endast admin
if (!isset($_SESSION["is_admin"]) || $_SESSION["is_admin"] != 1) {
header('Location: ../index.php');
exit;
}
require_once __DIR__ . '/../dbconnect.php';
// 1) Hämta result_id från GET
$result_id = $_GET['result_id'] ?? 0;
$result_id = (int)$result_id;
if ($result_id <= 0) {
echo "<p>Ogiltigt resultat-id.</p>";
exit;
}
// 2) Hämta övergripande info om resultatet (användare, test etc.)
$stmtResultInfo = $conn->prepare("
SELECT r.id AS result_id,
r.score,
r.taken_at,
t.test_name,
u.username
FROM quizdb_results r
JOIN quizdb_tests t ON r.test_id = t.id
JOIN quizdb_users u ON r.user_id = u.id
WHERE r.id = ?
");
$stmtResultInfo->bind_param("i", $result_id);
$stmtResultInfo->execute();
$resultInfoData = $stmtResultInfo->get_result();
$resultInfo = $resultInfoData->fetch_assoc();
if (!$resultInfo) {
echo "<p>Resultatet kunde inte hittas.</p>";
exit;
}
// 3) Hämta info om alla frågor + svarsalternativ som användaren valt
$stmtDetails = $conn->prepare("
SELECT q.question_text, a.answer_text, ua.is_correct
FROM quizdb_user_answers ua
JOIN quizdb_questions q ON ua.question_id = q.id
JOIN quizdb_answers a ON ua.answer_id = a.id
WHERE ua.result_id = ?
ORDER BY q.id
");
$stmtDetails->bind_param("i", $result_id);
$stmtDetails->execute();
$detailsResult = $stmtDetails->get_result();
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8" />
<title>Detaljer - Resultat</title>
</head>
<body>
<h1>Detaljer för resultat #<?php echo $resultInfo["result_id"]; ?></h1>
<p>
<strong>Användare:</strong> <?php echo htmlspecialchars($resultInfo["username"]); ?><br>
<strong>Testnamn:</strong> <?php echo htmlspecialchars($resultInfo["test_name"]); ?><br>
<strong>Poäng:</strong> <?php echo (int)$resultInfo["score"]; ?><br>
<strong>Genomförd:</strong> <?php echo $resultInfo["taken_at"]; ?>
</p>
<hr>
<h2>Valda svar</h2>
<?php if ($detailsResult->num_rows === 0) : ?>
<p>Inga svar registrerade för detta resultat.</p>
<?php else : ?>
<table border="1" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th>Fråga</th>
<th>Användarens svar</th>
<th>Rätt/Fel</th>
</tr>
</thead>
<tbody>
<?php while ($row = $detailsResult->fetch_assoc()) : ?>
<tr>
<td><?php echo htmlspecialchars($row["question_text"]); ?></td>
<td><?php echo htmlspecialchars($row["answer_text"]); ?></td>
<td style="<?php echo ($row["is_correct"] == 1) ? 'color:green;' : 'color:red;'; ?>">
<?php echo ($row["is_correct"] == 1) ? "Rätt" : "Fel"; ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php endif; ?>
</body>
</html>