<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>View Absence</title>
</head>
<body>
  <?php

// database connection
require 'database.php';

// to make it possible, we have to retrieve list of presents then generate the absent list
//  select all name that match the date request

//$date = $_POST['2025-8-22'];
// $sql = "Select checkingName from checking  where checkingDate = '$date'
// set 
// $firstName = SUBSTRING_INDEX(Name, ' ', 1),
// $lastName=  SUBSTRING_INDEX(Name, ' ', -1); (Insert into )

//  ";
  // // substring with variable
  // $FirstName = "SUBSTRING_INDEX(CheckingName, ' ', 1)";
  // $lastName = "SUBSTRING_INDEX(CheckingName, ' ', -1) ";

  $date = $_POST['date'];

  //   $sql = "SELECT *  FROM person_per
  // where  
  //  NOT EXISTS (SELECT DISTINCT firstname and lastname FROM checking where ChechingDate <> '$date') ;  ";// WHERE CheckingDate = '$date' Select all from person_per that is in checking where date is this date

  // $sql = "SELECT DISTINCT FirstName, LastName  FROM person_per where ChechingDate <> '$date'
  // UNION ALL 
  // SELECT DISTINCT firstname, lastname FROM checking ";


$sql = "SELECT FirstName, LastName from person_per";
$sql1 = "SELECT firstname, lastname from checking WHERE CheckingDate = '$date'";

$data = mysqli_query($conn, $sql);

$data1 = mysqli_query($conn, $sql1);





if ($data === false) {
  // code...
  echo mysqli_error($conn);
} else {
  // code...
  $person= mysqli_fetch_all($data, MYSQLI_ASSOC);
  

}

if ($data1 === false) {
  // code...
  echo mysqli_error($conn);
} else {
  // code...
  $checkinIn= mysqli_fetch_all($data1, MYSQLI_ASSOC);
  

}

$result = array_diff_key($person, $checkinIn);

//echo $result["FirstName"];

//$decode = json_decode($result);


//print_r($result);
echo "for that date $date";
//  foreach ($result as $x) {
//   $string1 = implode(" , ",  $x);
//  // echo "$string1 <br>";
//   //$tes= print_r($x["FirstName"] );
  
//   echo "<br>";
  
//   //echo "$string1  <br>";
//   //print_r("$string1 <br>");
//  }

?>
<!-- test table -->

             <?php foreach ($result as $x):  ?>
           <a href="testabsenceprofile.php?id=<?=$string1?>">   <?= $string1 = implode(" , ",  $x);?></a>
          
            

             <table id="Guests">
               <tr>
                 <!--<th>Name</th> -->
                 
               </tr>

               <tr>
                <td><?php $string1 ?></td>
                 
               </tr>
             </table>
           <?php endforeach; ?>
           
        

</body>
</html>