Files
intecsync/uebung10/api.php
2019-07-11 13:53:27 +02:00

26 lines
636 B
PHP

<?php
require_once(__DIR__ . '/Database.php');
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$db = new Database();
$n = 10;
if (isset($_GET['n'])) {
$n = $_GET['n'];
}
$questions = $db->getQuestions($n);
$fullarray[] = [];
for ($i = 0; $i < count($questions); $i++) {
$answers[] = array($questions['answer0'], $questions['answer1'], $questions['answer2']);
$jsonarray[] = array("id" => $questions['id'], "answers" => $answers, "solution" => $questions['solution']);
$fullarray[] = $jsonarray;
}
$questionsobj = json_encode($fullarray);
echo($questionsobj);
?>