<?php header("Content-Type:application/json");
if(isset($_GET['session']) && isset($_GET['semester_num']) && isset($_GET['course_code'])){
	
	include("../connect.php");
	
	$course_code=strtolower($_GET['course_code']);
	$ses_len=((int)strlen($_GET['session']))/2;
	$session=substr($_GET['session'],0,$ses_len).'/'.substr($_GET['session'],$ses_len);
	$semester_num=$_GET['semester_num'];
	$status='success';
	$matric_no='';
	
	$aga=mysqli_query($con,"select * from reg_course where LCASE(course_code)='$course_code' AND session='$session' AND semester_num='$semester_num'");
	
	if(mysqli_num_rows($aga)>0){
		while($cha=mysqli_fetch_assoc($aga)){
			$matric_no .=$cha['matric_no'].',';
		}
		
		$matric_no = substr_replace(trim($matric_no),"",-1);
		
		response($matric_no,$status);
	}else{
		response(NULL, 'failed');
	}
	
	}else{
		response(NULL, 'failed');
		}

function response($matric_no,$status){
	$response['matric_no'] = $matric_no;
	$response['status'] = $status;
	
	$json_response = json_encode($response);
	echo $json_response;
}
?>
