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

26 lines
579 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[] = [];
foreach($questions as $q) {
$answers[] = array($q['answer0'], $q['answer1'], $q['answer2']);
$jsonarray[] = array("id" => $q['id'], "answers" => $answers, "solution" => $q['solution']);
$fullarray[] = $jsonarray;
}
$questionsobj = json_encode($fullarray);
echo($questionsobj);
?>