<?php

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

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

    $uId = $_POST['uId'];

    $getQuizHistory = "SELECT `id`, `uId`, `quizname`, `icon`, `color`, `totalQuestions`, `questionAttempted`, `correctAnswers`, `wrongAnswers`, `entryFee`, `prize`, UNIX_TIMESTAMP(`date`) FROM `quizhistory` WHERE `uId` = '$uId' ORDER BY `id` DESC";

    $fetchHistory = mysqli_query($conn,$getQuizHistory);

    if($fetchHistory)
    {
        $response['statusCode'] = 0;
        $response['message'] = "Successful";
        while($row=$fetchHistory->fetch_assoc())
        {
            $response['quizHistory'] [] = $row; 
        }
    }
    else
    {
        $response['statusCode'] = 4;
        $response['message'] = 'Error in fetching quiz history';
    }

    echo json_encode($response);

?>