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

$dayQuery="";
 $month=$_POST['month'];
  $day=$_POST['day'];
  
  if($day=='ALL'){}
else{
$dayQuery=" and day ='$day'";
}

//fetch table rows from mysql db

$where ="where month = '$month'" . $dayQuery;
$select = "select firstname,lastname,level,department,sex ";
    $sql = $select."from student ".$where." union ".$select."from staff ".$where;
  
  $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);

    //close the db connection
    mysqli_close($con);

?>
