Show sourcecode
The following files exists in this folder. Click to view.
account.php
admin_register.php
create_quiz.php
create_tables.php
index.php
login.php
nav.css
nav.php
quiz.php
quiz_select.php
register.php
result_details.php
result_simple.php
submit_create_quiz.php
submit_quiz.php
result_simple.php
62 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
<?php
session_start();
include ('../../incl/dbconnect.php');
$test_id = isset($_GET['test_id']) ? $_GET['test_id'] : null; //Behövde lägga in eftersom att annars saknades test_id när jag skickar den vidare till result_details
try {
// Hämta alla resultat med användarnamn och poäng sorterat efter poäng
$sql = "SELECT u.username, r.poäng FROM results_quiz r
JOIN users_quiz u ON r.kund_id = u.id
ORDER BY r.poäng DESC";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error fetching results: " . $e->getMessage();
exit;
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Resultat - Enkel visning</title>
<link rel="stylesheet" href="nav.css">
</head>
<body>
<?php include ('nav.php'); ?>
<h2>Resultatlista</h2>
<table>
<thead>
<tr>
<th>Användarnamn</th>
<th>Poäng</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $row): ?>
<tr>
<td><?= htmlspecialchars($row['username']) ?></td>
<td><?= htmlspecialchars($row['poäng']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo "Debug: test_id är " . (isset($test_id) ? $test_id : "inte satt"); ?>
<br>
<a href="result_details.php?test_id=<?php echo urlencode($test_id); ?>">Vill du se ditt resultat mer detaljerat? (KLICKA TOBIAS)</a> <br>
<br>
<a href="index.php">Tillbaka till stratsidan</a>
</body>
</html>