<?php
include("../../db.php");
header('Content-Type: application/json');

$data = array();
$status = 0;

$attemptpaper = $db->getRows("select * from assignment_attempt_paper");
if(count($attemptpaper) > 0){
    $status =1;
    foreach($attemptpaper as $paper){

        $student = $db->getRow("select  * from student where idno='$paper[uid]' ");

        $paperdetail = $db->getRow("select * from assignment_paper where id='$paper[pid]' ");

        $total_que = $paper[correct] + $paper[wrong] + $paper[skipped];

        $chapterId = $paperdetail['chapter'];
        $chapterName = $db->getVal("SELECT subject FROM subject_new WHERE id = '$chapterId'");

        array_push($data, ["row_id"=>$paper[id], "student_id"=>"$paper[uid]", "name"=>"$student[name]","photo"=>"$student[photo]" ,"class"=>"$student[class]",
            "section"=>"$student[section]", "fname"=>"$student[fname]", "adm_no"=>"$student[admissionno]", "roll_no"=>"$student[fincome]",
            "paper_id"=>"$paper[pid]", "paper_dsc"=>"$paperdetail[paper_description]", "total_que"=>$total_que, "correct"=>$paper[correct],"wrong"=>$paper[wrong],
            "skipped"=>$paper[skipped], "chapter_name"=>$chapterName]);
    }
}

$array['status'] = $status;

$array['data'] = $data;

echo json_encode($array);

?>