[英]how to compare the two fields in php with different table in mysql?
//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. //这是我更新的代码,它现在将当前时间与mysql中保存的时间进行比较,但我的问题是它只与第一次添加的时间进行比较,我需要的是当前时间会将其与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
假设您在表
time_in
有一个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.准确地说,你应该给一个
teacher_id
在time_in
因此只有选择相应的老师的时间表。
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.虽然,这写得不好,但它的全部意义在于在评论中检查您的观点后,为您提供有关如何处理的想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.