Files
intecsync/cgi-bin/uebung09/questions-show.php
2019-07-04 09:06:34 +02:00

53 lines
1.2 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 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>$question->answer1</td>");
$color = ($question->solution == 2) ? "background-color: green" : "background-color: red";
echo("<td>$question->answer2</td>");
echo("<td>$question->solution</td>");
echo("<td></td>");
echo("</tr>");
}
echo <<<END
</table>
<br><br>
<a href="questions-create.php">Frage hinzufügen</a>
END;
?>