Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/projekt/quiz/

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)
<?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>