<?php

/*Student API*/


/*Fetching API*/


/* Attempt to connect to MySQL database */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'Restax_final');

define('DB_PASSWORD', 'Restax_final123');

define('DB_NAME', 'Restax_api_data'); 
; 

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

 $course=$request->getAttribute('course');
 $department=$request->getAttribute('department');
 $level_id=$request->getAttribute('level_id');
  $batch=$request->getAttribute('batch');
// $start_module='2';

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

$response=array();




//$sql="SELECT range_in,grade FROM set_grade WHERE course_id = '$course_id'AND dept_id = '$dept_id'AND level_id = '$level_id'AND start_module = '$start_module'";


// $sql="SELECT grade,range_in FROM set_grade WHERE course_id = '$course_id' AND start_module='$start_module' AND dept_id = '$dept_id' AND level_id='$level_id'";


// if(!empty($request->getParsedBody()['course']) && !empty($request->getParsedBody()['department']) && !empty($request->getParsedBody()['level_id'])){
// $sql="SELECT student_id,roll_number,student_name,email_id FROM student WHERE course = '$course' AND department='$department' AND level_id='$level_id'";
// }
// elseif(!empty($request->getParsedBody()['course']) && !empty($request->getParsedBody()['department'])){

// 	$sql="SELECT * FROM student WHERE course = '$course' AND department='$department'";
// }
if(isset($course)&&isset($department)&&isset($level_id)&&isset($batch)){

	$sql="SELECT DISTINCT batch FROM student WHERE course = '$course'AND department = '$department'AND level_id = '$level_id'AND batch = '$batch'AND status='1'";
}
elseif(isset($course)&&isset($department)&&isset($level_id)){

  $sql="SELECT DISTINCT batch FROM student WHERE course = '$course'AND department = '$department'AND level_id = '$level_id'AND status='1'";
}
elseif(isset($course)&&isset($department)){
	$sql="SELECT DISTINCT batch FROM student WHERE course = '$course'AND department = '$department'AND status='1'";
}
elseif(isset($course)){
	$sql="SELECT DISTINCT batch FROM student WHERE course = '$course'AND status='1'";
}
else{
	$sql="SELECT DISTINCT batch FROM student WHERE status='1'";
}


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

$data=array('grade' =>$department, 'id' =>$course);
 
	$response=array('status' => "true",'Message' => "Data updated successfully",'grade' => $data);
    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($user);


?>