<?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_id=$request->getParsedBody()['course_id'];                       
 $dept_id=$request->getParsedBody()['dept_id'];
 $level_id=$request->getParsedBody()['level_id'];
  $type=$request->getParsedBody()['type'];
// $start_module='2';

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

$response=array();



if(isset($course_id)&&isset($dept_id)&&isset($level_id)&&isset($type)){
$sql="SELECT * FROM set_grade WHERE course_id = '$course_id'AND dept_id = '$dept_id'AND level_id='$level_id'AND type='$type'";
}
elseif(isset($course_id)&&isset($dept_id)&&isset($level_id)){
$sql="SELECT * FROM set_grade WHERE course_id = '$course_id'AND dept_id = '$dept_id'AND level_id='$level_id'";
}
elseif(isset($course_id)&&isset($dept_id)){
$sql="SELECT * FROM set_grade WHERE course_id = '$course_id'AND dept_id = '$dept_id'";
}
elseif(isset($course_id)){
$sql="SELECT * FROM set_grade WHERE course_id = '$course_id'";
}
else{
	$sql="SELECT * FROM set_grade";
}
$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($user);






?>