Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/projects/quiz/

access-deneid.png
diagramresultat.php
insert-admin.php
login.php
logout.php
personliga-resultat.php
quiz-sida.php
ransa-quiz-session.php
ransa-skapa-quiz-session.php
resultat.php
session-variabler-unset.php
signin.php
skapa-inloggning-tabell.php
skapa-quiz-tabeller.php
skapa-quiz.php
start.php
tabort-kunder-quiz.php
åtkomst-nekad.php

resultat.php

109 lines UTF-8 Windows (CRLF)
<?php
  session_start
();
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    th{
      background-color:darkblue;
      color: white;
    }
    h2{
      margin:0;
    }
    table{
      border-collapse:collapse;
      margin:0;
      font-size:16px;
      text-align: left;
    }
    table,th,td{
      border:1px solid black;
    }
    th,td {
      padding: 10px;
    }
    tr:hover{
      background-color:#f1f1f1;
    }
    div{
      margin-left:30px;
      width:400px;
      display:flex;
      flex-direction:column;      
    }

  </style>
</head>
<body>
  <?php

  
class TableRows extends RecursiveIteratorIterator {
    function 
__construct($it) {
      
parent::__construct($itself::LEAVES_ONLY);
    }
  
    function 
current(): string {
      return 
"<td>" parent::current(). "</td>";
    }
  
    function 
beginChildren(): void {
      echo 
"<tr>";
    }
  
    function 
endChildren(): void {
      echo 
"</tr>" "\n";
    }
  }

  include (
'../../dbconnection.php');
  
?>
  <br>
  <a href="start.php">Tillbaka till start</a>
  <?php
  $quizerIdLista 
= array();
  
$quizerNamnLista = array();

  
  
$sql "SELECT * FROM quizer";
  
$stmt $dbconn->prepare($sql);
  
$stmt->execute();
  while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
    
array_push($quizerIdLista$res['id']);
    
array_push($quizerNamnLista$res['namn']);

  }
  
?>
  <div>
  <?php
  
for ($i=0$i count($quizerIdLista); $i++){
    echo 
"<table>";
    echo 
"<br> <br>";

    echo 
"<h2>"."Quiz ".$quizerNamnLista[$i]. "</h2>";
    echo 
"<tr><th>Användarnamn</th><th>Antal Rätt</th></tr>";
    
$stmt $dbconn->prepare(
    
"SELECT kunder.username, resultat.antalrätt 
     FROM resultat 
     JOIN kunder ON resultat.kundid = kunder.id
     WHERE quizid = 
$quizerIdLista[$i] 
     ORDER BY resultat.antalrätt DESC, kunder.username ASC"
);
    
$stmt->execute();
  
    
$result $stmt->setFetchMode(PDO::FETCH_ASSOC);
    foreach(new 
TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
      echo 
$v;
    }
  }
  
  
?>
  </div>

</body>
</html>