Webbserverprogrammering 1

Show sourcecode

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

webbserver/filmquiz/

api/
createroom.php
createtables.php
createuser.php
css/
dbconnection.php
game.php
index.php
login.php
logout.php
remove.php
rensa.php
results.php
waiting.php

results.php

54 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">
    <link href="css/stylesheet.css" rel="stylesheet">
    <title>Resultat</title>
</head>
<body>
    <?php
    
include("dbconnection.php");
    
/** @var PDO $dbconn */
    
$room_id $_SESSION['room_id'];
    if (
$_SESSION['username'] === null) {
        
header("Location: login.php");
        exit;
    }

    
$stmt $dbconn->prepare("
        SELECT u.username, COALESCE(s.points, 0) as points
        FROM fq_room_players rp
        JOIN fq_users u ON u.id = rp.user_id
        LEFT JOIN fq_scores s ON s.session_id = (
            SELECT id FROM fq_game_sessions WHERE room_id = :room_id
        ) AND s.user_id = rp.user_id
        WHERE rp.room_id = :room_id
        ORDER BY points DESC
    "
);
    
$stmt->execute([':room_id' => $room_id]);
    
$scores $stmt->fetchAll(PDO::FETCH_ASSOC);

    
$winner $scores[0];
    
$loser  $scores[1];
    
$draw   $winner['points'] === $loser['points'];
    
?>

    <h1>Spelet är slut!</h1>

    <?php if ($draw): ?>
        <h2>Oavgjort! <?php echo $winner['points']; ?> poäng vardera</h2>
    <?php else: ?>
        <h2><?php echo $winner['username']; ?> vinner med <?php echo $winner['points']; ?> poäng!</h2>
    <?php endif; ?>

    <h3>Slutresultat:</h3>
    <?php foreach ($scores as $score): ?>
        <p><?php echo $score['username']; ?><?php echo $score['points']; ?> poäng</p>
    <?php endforeach; ?>

    <br>
    <a href="index.php"><button>Tillbaka till menyn</button></a>

</body>
</html>