<?php

$con = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
$course_id = $request->getAttribute('course_id');
$season_id=$request->getAttribute('season_id');
$exams_id=$request->getAttribute('exams_id');
$paper=$request->getAttribute('paper');
$slots=$request->getAttribute('slots');

$response=array();

if(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($paper)&&isset($slots)){
$sql="SELECT create_slots.id, create_slots.course_id, create_slots.season_id, create_slots.exams_id, create_slots.paper, create_slots.slots,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode
 FROM (create_slots INNER JOIN course ON course.course_id=create_slots.course_id 
 INNER JOIN season ON season.id=create_slots.season_id
 INNER JOIN Exams ON Exams.id=create_slots.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper)
 WHERE create_slots.course_id='$course_id' AND create_slots.season_id='$season_id' AND create_slots.exams_id='$exams_id'
 AND create_slots.paper='$paper'  AND create_slots.slots='$slots'";
}

elseif(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($paper)){
$sql="SELECT create_slots.id, create_slots.course_id, create_slots.season_id, create_slots.exams_id, create_slots.paper, create_slots.slots,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode
 FROM (create_slots INNER JOIN course ON course.course_id=create_slots.course_id 
 INNER JOIN season ON season.id=create_slots.season_id
 INNER JOIN Exams ON Exams.id=create_slots.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper)
 WHERE create_slots.course_id='$course_id' AND create_slots.season_id='$season_id' AND create_slots.exams_id='$exams_id'
 AND create_slots.paper='$paper'";
}

elseif(isset($course_id)&&isset($season_id)&&isset($exams_id)){
$sql="SELECT create_slots.id, create_slots.course_id, create_slots.season_id, create_slots.exams_id, create_slots.paper, create_slots.slots,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode
 FROM (create_slots INNER JOIN course ON course.course_id=create_slots.course_id 
 INNER JOIN season ON season.id=create_slots.season_id
 INNER JOIN Exams ON Exams.id=create_slots.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper)
 WHERE create_slots.course_id='$course_id' AND create_slots.season_id='$season_id' AND create_slots.exams_id='$exams_id'";
}


elseif(isset($course_id)&&isset($season_id)){
$sql="SELECT create_slots.id, create_slots.course_id, create_slots.season_id, create_slots.exams_id, create_slots.paper, create_slots.slots,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode
 FROM (create_slots INNER JOIN course ON course.course_id=create_slots.course_id 
 INNER JOIN season ON season.id=create_slots.season_id
 INNER JOIN Exams ON Exams.id=create_slots.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper)
 WHERE create_slots.course_id='$course_id' AND create_slots.season_id='$season_id'";
}

elseif(isset($course_id)){
$sql="SELECT create_slots.id, create_slots.course_id, create_slots.season_id, create_slots.exams_id, create_slots.paper, create_slots.slots,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode
 FROM (create_slots INNER JOIN course ON course.course_id=create_slots.course_id 
 INNER JOIN season ON season.id=create_slots.season_id
 INNER JOIN Exams ON Exams.id=create_slots.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper)
 WHERE create_slots.course_id='$course_id'";
}

else{
$sql="SELECT create_slots.id, create_slots.course_id, create_slots.season_id, create_slots.exams_id, create_slots.paper, create_slots.slots,
course.course_name, season.seasonname, Exams.examname, set_papers.papers_shortcode
 FROM (create_slots INNER JOIN course ON course.course_id=create_slots.course_id 
 INNER JOIN season ON season.id=create_slots.season_id
 INNER JOIN Exams ON Exams.id=create_slots.exams_id
 INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper
 )";
}


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

    while ($row[]=mysqli_fetch_assoc($result)) {  

      $user=$row;

	}


echo json_encode($user);


?>