<?php

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

    require '../config/conn.php';
    
    $categoryId=$_POST['categoryId'];

    if($categoryId!=0)
    {
        $getAllQuiz="SELECT * FROM `quizzes` WHERE `categoryId`='$categoryId'";
    }
    else
    {
        $getAllQuiz="SELECT * FROM `quizzes` WHERE 1";
    }
    
    $fetchQuiz=mysqli_query($conn,$getAllQuiz);

    if($fetchQuiz)
    {
        if(mysqli_num_rows($fetchQuiz)>0)
        {
            $response['statusCode']=0;
            $response['message']="Data Fetched";

            while($row=$fetchQuiz->fetch_assoc())
            {
                $response['quizList'][]=$row;
            }
        }
        else
        {
            $response['statusCode']=1;
            $response['message']="No Quiz";
        }
    }
    else
    {
        $response['statusCode']=4;
        $response['message']="Error in fetching quiz";
    }

    echo json_encode($response);

?>