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

diagramresultat.php

84 lines UTF-8 Windows (CRLF)
<?php
  session_start
();
  include (
'../../dbconnection.php');
?>
<br>
<?php
$antalRättLista 
= array();

$sql "SELECT * FROM resultat";
$stmt $dbconn->prepare($sql);
$stmt->execute();
while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
  
array_push($antalRättLista$res['antalrätt']);
}
$countValues array_count_values($antalRättLista);

$värden = [
  isset(
$countValues[5]) ? $countValues[5] : 0,
  isset(
$countValues[4]) ? $countValues[4] : 0,
  isset(
$countValues[3]) ? $countValues[3] : 0,
  isset(
$countValues[2]) ? $countValues[2] : 0,
  isset(
$countValues[1]) ? $countValues[1] : 0,
  isset(
$countValues[0]) ? $countValues[0] : 0
];
?>

<!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>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
</head>
<body>
  <canvas id="myChart" style="width:100%;max-width:600px"></canvas>

  <script>
  const xValues = ["5", "4", "3", "2", "1", "0"];
  const yValues = <?php echo json_encode($värden); ?>;
  const barColors = ["#800080", "#6A0DAD", "#571BCE", "#3F3FE0", "#2862F0", "#0080FF"];

    new Chart("myChart", {
      type: "bar",
      data: {
        labels: xValues,
        datasets: [{
          backgroundColor: barColors,
          data: yValues
        }]
        },
        options: {
          legend: {display: false},
          title: {
            display: true,
            text: "Antal rätt totalt över alla Quiz"
          },

          scales: {
            xAxes: [{
              scaleLabel: {
                display: true,
                labelString: "Antal rätt"
              }
            }],

            yAxes: [{
              scaleLabel: {
                display: true,
                labelString: "Antal tagna Quiz"
              },
              ticks: {
                beginAtZero: true
              }
            }]
          }
      }
    });
  </script>
  <a href="start.php">Tillbaka till start</a>
</body>
</html>