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

  
  $course_id=$request->getAttribute('course_id');
  $session_id = $request->getAttribute('session_id');
  $dept_id = $request->getAttribute('dept_id');
  $level_id = $request->getAttribute('level_id');
  $year=$request->getAttribute('year');
  $term = $request->getAttribute('term');
  $section = $request->getAttribute('section');
  $roll_number=$request->getAttribute('roll_number');
  $student_name = $request->getAttribute('student_name');
  $detained = $request->getAttribute('detained');
  $buffered=$request->getAttribute('buffered');
  $papers_undertaking=$request->getAttribute('papers_undertaking');
  $suply_papers=$request->getAttribute('suply_papers');
  $institute_name=$request->getAttribute('insitute_name');
  $institute_no=$request->getAttribute('institute_no');
  $password=$request->getAttribute('password');
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$response=array();
if(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)&&isset($section)){
$sql="SELECT set_student_season.*, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id WHERE set_student_season.course_id='$course_id' AND  set_student_season.session_id='$session_id' AND set_student_season.dept_id='$dept_id' AND set_student_season.level_id='$level_id' AND set_student_season.year='$year' AND set_student_season.term='$term' AND set_student_season.section='$section'";
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)){
$sql="SELECT set_student_season.*, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id WHERE set_student_season.course_id='$course_id' AND  set_student_season.session_id='$session_id' AND set_student_season.dept_id='$dept_id' AND set_student_season.level_id='$level_id' AND set_student_season.year='$year' AND set_student_season.term='$term'";
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)){
$sql="SELECT set_student_season.*, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id WHERE set_student_season.course_id='$course_id' AND  set_student_season.session_id='$session_id' AND set_student_season.dept_id='$dept_id' AND set_student_season.level_id='$level_id' AND set_student_season.year='$year'";
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)){
$sql="SELECT set_student_season.*, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id WHERE set_student_season.course_id='$course_id' AND  set_student_season.session_id='$session_id' AND set_student_season.dept_id='$dept_id' AND set_student_season.level_id='$level_id'";
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)){
$sql="SELECT set_student_season.id, set_student_season.course_id, set_student_season.session_id, set_student_season.dept_id, set_student_season.level_id, set_student_season.year, set_student_season.term, set_student_season.section, set_student_season.rollnumber,set_student_season.student_name,set_student_season.detained, set_student_season.buffered,set_student_season.papers_undertaking,set_student_season.suply_papers,set_student_season.Institute_name, set_student_season.institute_code, set_student_season.password, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id WHERE set_student_season.course_id='$course_id' AND  set_student_season.session_id='$session_id' AND set_student_season.dept_id='$dept_id'";
}

elseif(isset($course_id)&&isset($session_id)){
$sql="SELECT set_student_season.id, set_student_season.course_id, set_student_season.session_id, set_student_season.dept_id, set_student_season.level_id, set_student_season.year, set_student_season.term, set_student_season.section, set_student_season.rollnumber,set_student_season.student_name,set_student_season.detained, set_student_season.buffered,set_student_season.papers_undertaking,set_student_season.suply_papers,set_student_season.Institute_name, set_student_season.institute_code, set_student_season.password, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id WHERE set_student_season.course_id='$course_id' AND  set_student_season.session_id='$session_id'";
}
elseif(isset($course_id)){
$sql="SELECT set_student_season.id, set_student_season.course_id, set_student_season.session_id, set_student_season.dept_id, set_student_season.level_id, set_student_season.year, set_student_season.term, set_student_season.section, set_student_season.rollnumber,set_student_season.student_name,set_student_season.detained, set_student_season.buffered,set_student_season.papers_undertaking,set_student_season.suply_papers,set_student_season.Institute_name, set_student_season.institute_code, set_student_season.password, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id WHERE set_student_season.course_id='$course_id'";
}
else{
$sql="SELECT set_student_season.id, set_student_season.course_id, set_student_season.session_id, set_student_season.dept_id, set_student_season.level_id, set_student_season.year, set_student_season.term, set_student_season.section, set_student_season.rollnumber,set_student_season.student_name,set_student_season.detained, set_student_season.buffered,set_student_season.papers_undertaking,set_student_season.suply_papers,set_student_season.Institute_name, set_student_season.institute_code, set_student_season.password, course.course_name, department.dept_name, department.dept_shortcode, level.level_name, level.level_shortcode from set_student_season INNER JOIN course ON course.course_id=set_student_season.course_id
		INNER JOIN department ON department.dept_id=set_student_season.dept_id
		INNER JOIN level ON level.level_id=set_student_season.level_id";
}



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

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

      $user=$row;



    }



echo json_encode($user);




?>