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

if($_POST['level'] == "All") {$level = "level like '%'";} else {$level = "level='" .$_POST['level']."'";}
if($_POST['sex'] == "All"){$sex = "sex like '%'";}else{$sex = "sex= '".$_POST['sex']."'";}
if($_POST['department'] == "All"){$department = "department like '%'";}else{$department = "department= '" .$_POST['department']."'";}
if($_POST['faculty'] == "All"){$faculty = "faculty like '%'";}else{$faculty = "faculty= '".$_POST['faculty']."'";}


$sql = "SELECT * FROM staff where ".$level." and ".$sex." and ".$department." and ".$faculty;

//echo $sql;
$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);

mysqli_close($con);

?>
