<?php

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

$course_id = $request->getAttribute('course_id');
$exams_id=$request->getAttribute('exams_id');
$date=$request->getAttribute('date');
$time=$request->getAttribute('time');
$slots=$request->getAttribute('slots');

$response=array();

if(isset($course_id)&&isset($exams_id)&&isset($date)&&isset($time)){
    $sql="SELECT distinct pwe_answersheet_submit.papers_shortcode, pwe_answersheet_submit.slots, pwe_answersheet_submit.course_id,
    pwe_answersheet_submit.exams_id, pwe_answersheet_submit.date, pwe_answersheet_submit.time, Exams.examname, course.course_name
    FROM pwe_answersheet_submit   INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id 
         INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id  WHERE pwe_answersheet_submit.course_id='$course_id' AND pwe_answersheet_submit.exams_id='$exams_id'
     AND pwe_answersheet_submit.date='$date'  AND pwe_answersheet_submit.time='$time' ";
    }
elseif(isset($course_id)&&isset($exams_id)&&isset($date)){
    $sql="SELECT distinct pwe_answersheet_submit.papers_shortcode, pwe_answersheet_submit.slots, pwe_answersheet_submit.course_id,
    pwe_answersheet_submit.exams_id, pwe_answersheet_submit.date, pwe_answersheet_submit.time, Exams.examname, course.course_name
    FROM pwe_answersheet_submit   INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id 
         INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id  WHERE pwe_answersheet_submit.course_id='$course_id' AND pwe_answersheet_submit.exams_id='$exams_id'
     AND pwe_answersheet_submit.date='$date' ";
    }
elseif(isset($course_id)&&isset($exams_id)){
    $sql="SELECT distinct pwe_answersheet_submit.papers_shortcode, pwe_answersheet_submit.slots, pwe_answersheet_submit.course_id,
    pwe_answersheet_submit.exams_id, pwe_answersheet_submit.date, pwe_answersheet_submit.time, Exams.examname, course.course_name
    FROM pwe_answersheet_submit   INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id 
         INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id    WHERE pwe_answersheet_submit.course_id='$course_id' AND pwe_answersheet_submit.exams_id='$exams_id' ";
    }
elseif(isset($course_id)){
$sql="SELECT distinct pwe_answersheet_submit.papers_shortcode, pwe_answersheet_submit.slots, pwe_answersheet_submit.course_id,
pwe_answersheet_submit.exams_id, pwe_answersheet_submit.date, pwe_answersheet_submit.time, Exams.examname, course.course_name
FROM pwe_answersheet_submit   INNER JOIN Exams ON Exams.id=pwe_answersheet_submit.exams_id 
     INNER JOIN course ON course.course_id=pwe_answersheet_submit.course_id 
      WHERE pwe_answersheet_submit.course_id='$course_id' ";
}


$result=mysqli_query($con,$sql);

$i=0;
while ($row[]=mysqli_fetch_assoc($result)) {

$exams=$row;

$papers_shortcode = $exams[$i][papers_shortcode];
$slots = $exams[$i][slots];
$course_name = $exams[$i][course_name];
$examname = $exams[$i][examname];
$course_id = $exams[$i][course_id];
$exams_id = $exams[$i][exams_id];
$date = $exams[$i][date];
$time = $exams[$i][time];


$keys[] = array("papers_shortcode"=>"$papers_shortcode","slots"=>"$slots",
"course_name"=>"$course_name","examname"=>"$examname","course_id"=>"$course_id","exams_id"=>"$exams_id"
,"date"=>"$date","time"=>"$time");
}
echo json_encode($keys);

?>