<?php

    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json");
    header("Accept: application/json");

    require '../config/conn.php';

    $difficulty =$_POST['difficulty'];
    $quizId = $_POST['quizId'];
    $questionLimit=$_POST['questionLimit'];

    
    $getQuizQuestions="SELECT * FROM `questions` WHERE `quizId`='$quizId' AND `difficulty` = '$difficulty' ORDER BY RAND() LIMIT $questionLimit";
    $fetchQuestions=mysqli_query($conn,$getQuizQuestions);

    if($fetchQuestions)
    {
        if(mysqli_num_rows($fetchQuestions)>0)
        {
            $response['statusCode']=0;
            $response['message']='Questions fetched successfully';

            while($row=$fetchQuestions->fetch_assoc())
            {
                $response['questionsList'][]=$row;
            }
        }
        else
        {
            $response['statusCode']=1;
            $response['message']='No questions found';
        }
    }
    else
    {
            $response['statusCode']=4;
            $response['message']='Error in fetching questions';
    }

    echo json_encode($response);




?>