<?php 
$con= new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

$course_id = $request->getAttribute('course_id');
$exams_id= $request->getAttribute('exams_id');
$papers_shortcode = $request->getAttribute('papers_shortcode');

$response=array();

if(isset($course_id)&&isset($exams_id)&&isset($papers_shortcode)){
$sql="SELECT pwe_answersheet_submit.course_id, pwe_answersheet_submit.exams_id, pwe_answersheet_submit.roll_number, 
pwe_answersheet_submit.score, set_marks.max_marks, course.course_name, Exams.examname 
FROM pwe_answersheet_submit
INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id
INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id
INNER JOIN set_marks ON set_marks.paper=pwe_answersheet_submit.papers_id
WHERE pwe_answersheet_submit.course_id='$course_id' AND pwe_answersheet_submit.exams_id='$exams_id' 
AND pwe_answersheet_submit.papers_shortcode='$papers_shortcode' ";
}
elseif(isset($course_id)&&isset($exams_id)){
    $sql="SELECT pwe_answersheet_submit.course_id, pwe_answersheet_submit.exams_id, pwe_answersheet_submit.roll_number, 
    pwe_answersheet_submit.score, set_marks.max_marks, course.course_name, Exams.examname 
    FROM pwe_answersheet_submit
    INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id
    INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id
    INNER JOIN set_marks ON set_marks.paper=pwe_answersheet_submit.papers_id
    WHERE pwe_answersheet_submit.course_id='$course_id' AND pwe_answersheet_submit.exams_id='$exams_id' 
   ";
    }
    elseif(isset($course_id)){
        $sql="SELECT pwe_answersheet_submit.course_id, pwe_answersheet_submit.exams_id, pwe_answersheet_submit.roll_number, 
        pwe_answersheet_submit.score, set_marks.max_marks, course.course_name, Exams.examname 
        FROM pwe_answersheet_submit
        INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id
        INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id
        INNER JOIN set_marks ON set_marks.paper=pwe_answersheet_submit.papers_id
        WHERE pwe_answersheet_submit.course_id='$course_id'  
       ";
        }
$result=mysqli_query($con,$sql);
while($row[]=mysqli_fetch_assoc($result)){
    $user=$row;
}

echo json_encode($user);
?>
