<?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');


// Check connection

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$response=array();


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

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

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




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

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

      $user=$row;

//      $array1 = array("5","26","38","42");

// $array2 = array("15","36","38","42");

//      $user = array_intersect($array1, $array2);



    }
// foreach ($user as &$value) {
//     $intersect[] = $value;

//        $providers = array_intersect($intersect[$value]);

// }
      // echo json_encode($course_id);
      // echo json_encode($dept_id);


echo json_encode($user);





?>