<?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);

foreach($questions as $q) {
        $answers = array($q['answer0'], $q['answer1'], $q['answer2']);
        $jsonarray = array("id" => $q['id'], "question" => $q['question'], "answers" => $answers, "solution" => $q['solution']);
        $fullarray[] = $jsonarray;
}


$questionsobj = json_encode($fullarray);
echo($questionsobj);
?>
