如何将php中的两个字段与mysql中的不同表进行比较?

  1. //here is my updated code it now compares the current time with the saved time in mysql but my problem is it only compares with the first added time what I need is the current time will compare it to the nearest time saved in mysql.

             <?php
            //Include the database configuration
            include 'config.php';
            //Get the data of the selected teacher
            $teacher = $dbconnect->prepare("SELECT * FROM teacher_info
            WHERE IMEI = ? AND NFC = ?");
            $teacher->bindValue(1,$_GET['IMEI']);
            $teacher->bindValue(2,$_GET['NFC']);
            $teacher->execute();
            //Get the data
            $teacher_info = $teacher->fetch();
    
    
        //If there is such a teacher let the teacher enter
        if(!empty($teacher_info))
        {
            $time_out = $dbconnect->prepare("INSERT INTO time_out (teacher_id,name,NFC,IMEI,time_out) VALUES (?,?,?,?,NOW())");
            $time_out->bindValue(1,$teacher_info['teacher_id']);
            $time_out->bindValue(2,$teacher_info['name']);
            $time_out->bindValue(3,$teacher_info['NFC']);
            $time_out->bindValue(4,$teacher_info['IMEI']);
            $time_out->execute();
        }
        ?>
        <!doctype html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Welcome!</title>
        </head>
        <body>
        <h1>
            <?php
            //If there is such a teacher,welcome him/her
            if(!empty($teacher_info))
            {
                echo 'Welcome '.$teacher_info['name'].'! Your NFC is '.$teacher_info['NFC'];
            }
            else
            {
                echo 'You are not registered.';
            }
            ?>
        </h1>
    
    
    
        </body>
        </html>
    
    
       //Hope you can help me out
    

Assuming that you have a time_in column in the table time_in

if($stmt = $dbconnect->prepare("SELECT time_in from time_in")){
$stmt->bind_param("s", $time_in); 
$stmt->execute(); 
$cur_time = time();
if($time_in === $cur_time){
echo "Teacher is on time";
}
}

This is mainly an idea about how things should be going. There's always room for improvement. To be precise, you should give a teacher_id in the time_in table so that the respective teacher's time is selected only.

EDIT:

 if($stmt = $dbconnect->prepare("SELECT time_in from time_in")){
   $stmt->bind_param("s", $time_in); 
   $stmt->execute(); 
 if($stmtt = $dbconnect->prepare("SELECT time from profschedule")){
  $stmtt->bind_param("s", $time); 
  $stmt->execute(); 
 if($time_in === $time)
  echo "Teacher is on time";
}}}

Although, this is poorly written but the whole point of it is to give you the IDEA about how to approach after inspecting your perspective in the comments.