Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将时间与最近的计划时间进行比较_Php_Mysql - Fatal编程技术网

Php 如何将时间与最近的计划时间进行比较

Php 如何将时间与最近的计划时间进行比较,php,mysql,Php,Mysql,有人能帮我修复这个代码吗。我需要的是让当前时间与“from”列中最近保存的时间表进行比较 因为当前时间只是将其与第一个添加的计划进行比较 代码: 欢迎 什么是IMEI和NFC?您应该能够使用now()将时间与当前时间进行比较。键入链接后,IMEI和NFC将从数据库中获取,它在数据库中具有相应的时间安排。一旦链接打开,它将比较当前时间和计划时间。但它只会与数据库中的第一个计划进行比较,如果您循环$teacher->fetch,您将获得所有记录。。。或者,您应该能够在SQL中执行逻辑。这是我们数据

有人能帮我修复这个代码吗。我需要的是让当前时间与“from”列中最近保存的时间表进行比较

因为当前时间只是将其与第一个添加的计划进行比较

代码:


欢迎

什么是
IMEI
NFC
?您应该能够使用
now()
将时间与当前时间进行比较。键入链接后,IMEI和NFC将从数据库中获取,它在数据库中具有相应的时间安排。一旦链接打开,它将比较当前时间和计划时间。但它只会与数据库中的第一个计划进行比较,如果您循环
$teacher->fetch
,您将获得所有记录。。。或者,您应该能够在SQL中执行逻辑。这是我们数据库的图像。它有两个保存的时间表。我们的代码仅将当前时间与第一次添加的计划进行比较。对不起。这是照片的新链接
                <?php
            //Include the database configuration
            include 'config.php';
            //Get the data of the selected teacher
            $teacher = $dbconnect->prepare("SELECT * FROM time WHERE IMEI = ? AND NFC = ?");
            $teacher->bindValue(1,$_GET['IMEI']);
            $teacher->bindValue(2,$_GET['NFC']);
            $teacher->execute();
            //Get the data
            $time = $teacher->fetch();
            //Store the current time
            $current_time = new DateTime();
            //Placeholder variables
            $time_difference = 0;
            $remark = "";
            //If there is such a teacher let the teacher enter
            if(!empty($time))
            {   

                //Get the time difference
                $time_difference = round( (strtotime($current_time->format('H:i:s')) - strtotime($time['From'])) / 60 );
                //Check if the professor is late or not
                //If the time difference is negative he/she is early
                if($time_difference < 0)
                {
                    $remark = 'Sir why are you so early?';
                }
                //If the prof is on time which is 0 time difference or less than 15 minutes
                else if($time_difference == 0 || $time_difference < 15)
                {
                    $remark = "Sir it's a miracle you are on time";
                }
                //Oh come on why are you so late Sir?Porn marathon at night?
                else if($time_difference == 15 || $time_difference > 15)
                {
                    $remark = 'Sir why are you late?';
                }

                $time_in = $dbconnect->prepare("INSERT INTO time_in (teacher_id,name,NFC,IMEI,time_in,remarks) VALUES (?,?,?,?,?,?)");
                $time_in->bindValue(1,$time['teacher_id']);
                $time_in->bindValue(2,$time['name']);
                $time_in->bindValue(3,$time['NFC']);
                $time_in->bindValue(4,$time['IMEI']);
                $time_in->bindValue(5,$current_time->format('H:i:s'));
                $time_in->bindValue(6,$remark);
                $time_in->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($time))
                {
                    echo 'Welcome '.$time['name'].'! Your NFC is '.$time['NFC'];
                    echo '</br>';
                    echo 'Time in at: '.$current_time->format('H:i:s');
                    //This is just a temporary display to show the time difference for testing.Kindly delete it later
                    echo '</br>';
                    echo 'Time difference: '.$time_difference;
                    //Display remark
                    echo '</br>';
                    echo 'Remark:'.$remark;
                }
                else
                {
                    echo 'You are not registered.';
                }
                ?>
            </h1>
            </body>
            </html>