<?php

include "connection.php";
include "validation.php";

$json = file_get_contents("php://input");
$data = json_decode($json, true);

$lesson = $data["lesson"];
$medium = $data["medium1"];

if ($lesson == 0) {
    $response["message"] = "Please Select Lesson First!";
}else if($lesson == null){
    $response["message"] = "Please Select Lesson First!";
} else {
    $rs = Database::search("SELECT * FROM `mcq` WHERE `lesson_id` = '" . $lesson . "' AND `medium_id` = '" . $medium . "' ");
    $value = [];

    if ($rs) {
        while ($row = $rs->fetch_assoc()) {
            $value[] = $row;
        }


        $response = [
            "status" => true,
            "data" => $value,
        ];
    } else {

        $response = [
            "status" => false,
            "message" => "Failed to retrieve data."
        ];
    }
}


header("Content-Type: application/json");
echo json_encode($response);
