如何比较距离最近的预定时间的时间

时间:2015-09-19 13:32:09

标签: php mysql

有人可以帮我解决这个问题。我需要的是让当前时间将其与列中的最近保存的时间表进行比较"来自"

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

代码:

                <?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>

0 个答案:

没有答案