<?php

header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Content-Type: application/json; charset=UTF-8");

include_once("../database.php");

if($_SERVER['REQUEST_METHOD'] === 'GET'){
    $sql1 = "SELECT Now()";
    $currtime = $mysqli->query($sql1);
    $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";

    $data = [];
    if($result = mysqli->query($sql2)){
        while($row = mysql_fetch_assoc($request)){
            array_push($data,$row);
        }
        echo json_encode($data);
    }
    else{
        http_response_code(404);
    }
}

?>
