<?php

 require ('../credentials.php');
$con=mysqli_connect(HOST, USERNAME, PASSWORD, DBNAME)or die("cannot connect"); 

if(isset($_POST['user_id'])){

$mat_no =$_POST['user_id'];
$sql3 = "SELECT * FROM student where user_id = '$mat_no'";
$result2 = mysqli_query($con, $sql3) or die("Error in Selecting " . mysqli_error($con));
$level="";
$category=$_POST['category'];
    while($row =mysqli_fetch_assoc($result2)){
		$faculty=$row['faculty'];
		$dept=$row['department'];
		$level=$row['level'];
		$sex=$row['sex'];
		//echo $sex;
			$level1=$faculty."_".$dept."_".$level."_".$sex;
		}
	
	$sql = "SELECT * FROM news where target ='$level1' and category ='$category' order by date desc";
	
	

$result = mysqli_query($con, $sql) or die("Error in Selecting " . mysqli_error($con));
//create an array
    $emparray = array();
    while($row =mysqli_fetch_assoc($result)){
		$emparray[] = $row;}
		
		
		
echo json_encode($emparray);

}




 else {
    // required post params is missing
    $response["error"] = TRUE;
    $response["error_msg"] = "no user_id found";
    echo json_encode($response);
}


mysqli_close($con);

?>
