Files
intecsync/cgi-bin/uebung09/questions-show.php
2019-07-04 12:41:52 +02:00

58 lines
1.5 KiB
PHP

<?php
require_once(__DIR__ . '/Database.php');
echo <<<END
<link rel="stylesheet" href="style.css">
<h1>Fragen anzeigen</h1>
<table>
<tr>
<td>Frage</td>
<td>Antwort0</td>
<td>Antwort1</td>
<td>Antwort2</td>
<td></td>
<td></td>
</tr>
END;
$db = new Database();
$questions = $db->getQuestions();
//This will convert the array into objects for easier access.
//The conversion is ugly but does the job (I'm used to the laravel collections)
$questionsobj = json_decode(json_encode($questions), false);
foreach($questionsobj as $question) {
echo("<tr>");
echo("<td>$question->question</td>");
$color = ($question->solution == 0) ? "background-color: green" : "background-color: red";
echo("<td style='$color'>$question->answer0</td>");
$color = ($question->solution == 1) ? "background-color: green" : "background-color: red";
echo("<td style='$color'>$question->answer1</td>");
$color = ($question->solution == 2) ? "background-color: green" : "background-color: red";
echo("<td style='$color'>$question->answer2</td>");
echo <<<END
<td><form action="questions-edit.php" method="get"><button name="id" value="$question->id">Bearbeiten</button></form></td>
<td><form action="questions-delete.php" method="post"><button name="id" value="$question->id">Löschen</button></form></td>
</tr>
END;
}
echo <<<END
</table>
<br><br>
<a href="questions-create.php">Frage hinzufügen</a>
END;
?>