Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbserver/Projekt1/

createquiz.php
createtable.php
dbconnection.php
index.php
login.php
myquiz.php
registrera.php
results.php
results2.php
takequiz.php

results2.php

42 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php
include "dbconnection.php";
    
/** @var PDO $dbconn */
$quiz_id = (int)$_GET['quiz_id'];

$stmt $dbconn->prepare(
    
"SELECT users.namn, results.score
     FROM results
     JOIN users ON users.id = results.user_id
     WHERE results.quiz_id = :quiz
     ORDER BY results.score DESC, users.namn ASC"
);
$stmt->execute([':quiz' => $quiz_id]);

$list $stmt->fetchAll();

$listHtml "";
foreach (
$list as $row) {
    
$name htmlspecialchars($row['namn']);
    
$score $row['score'];

    
$listHtml .= "<li>$name - $score poäng</li>";
}
?>

<h1>Resultat</h1>

<ul>
<?= $listHtml ?>
</ul>

<a href="index.php">Tillbaka</a>
</body>
</html>