Webbserv1: Källkod
Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/projects/quiz/

quiz.php
quiz_create.php
quiz_created.php
quiz_home.php
quiz_login.php
quiz_results.php
quiz_signup.php

quiz_results.php

52 lines UTF-8 Windows (CRLF)
<!doctype html>
<html>

<body>
<?php
  
include ('../../dbconnection.php');
?>
<form method="POST" action="">
    Välj quiz: 
    <select name="quizChoice">
      <?php
        $sql 
"SELECT * FROM quiz";
        
$stmt $dbconn->prepare($sql);
  
        
$stmt->execute();
  
        while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
          
?>
          <option value="<?php echo htmlentities($res['id']);?>"><?php echo htmlentities($res['quizName']);?></option>
          <?php
        
}
      
?>
    </select>
    <input type="submit" value="Välj quiz"><br><br>
</form>
<?php

  
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
$quizId $_POST["quizChoice"];
    
$sql "SELECT results.*, quizusers.user 
    FROM results 
    INNER JOIN quizusers ON results.userId = quizusers.id 
    WHERE results.quizId = '
$quizId
    ORDER BY results.correctAmount DESC"
;
    
$stmt $dbconn->prepare($sql);

    
$data = array();  
    
$stmt->execute($data);
    
$output "<table><caption>Resultat</caption><td>Spelare</td><td>Antal rätt</td>";
    while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
    
$output .= "<tr>".
    
"<td>".htmlentities($res['user'])."</td>".
    
"<td>".htmlentities($res['correctAmount'])."</td>".
    
"</tr>";
}

$output .= "</table>";
echo 
$output;
  }
?>
</body>
</html>