Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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,我正在开发一个会议室预订系统,我会选择他们想要预订房间的时间段。现在我有两个时间段: 2016-06-14 13:00:07as from_time field和2016-06-14 05:00:07as to_time field在我的数据库中。现在我必须检查给定的周期是否与数据库中的任何其他给定周期重叠。怎么做? 要存储数据:我的代码: $date = mysql_real_escape_string($_POST['date']); $date1= mysql_real_escap

我正在开发一个会议室预订系统,我会选择他们想要预订房间的时间段。现在我有两个时间段:
2016-06-14 13:00:07
as from_time field和
2016-06-14 05:00:07
as to_time field在我的数据库中。现在我必须检查给定的周期是否与数据库中的任何其他给定周期重叠。怎么做? 要存储数据:我的代码:

$date = mysql_real_escape_string($_POST['date']);
    $date1= mysql_real_escape_string($_POST['date1']);
    $from=mysql_real_escape_string($_POST['date2']);
    $to=mysql_real_escape_string($_POST['date3']);

    $from = strtotime($from);
    $to = strtotime($to);

    $subfrom =strtotime('-30 minutes',$from);
    $addto = strtotime('+30 minutes',$to);

    $from = date('Y-m-d H:i:s',$from);
    $to = date('Y-m-d H:i:s',$to);

    $subfrom = date('Y-m-d H:i:s',$subfrom);
    $addto =  date('Y-m-d H:i:s',$addto);

    $id = mysql_real_escape_string($_POST['faculty_id']);
    $name = mysql_real_escape_string($_POST['faculty_name']);
    $div = mysql_real_escape_string($_POST['division']);
    $school = mysql_real_escape_string($_POST['s_name']);
    $email = mysql_real_escape_string($_POST['email']);
    $contact = mysql_real_escape_string($_POST['contact_no']);
    $intercom = mysql_real_escape_string($_POST['intercom']);
    $purpose = mysql_real_escape_string($_POST['purpose']);
    if($purpose=='university lecture')
        $purpose = "university lecture";
    else if($purpose=='guest lecture')
        $purpose = "guest lecture";
    else if($purpose=='PHD Oral Exam')
        $purpose = "PHD Oral Exam";
    else if($purpose=='Placement Interview')
        $purpose = "Placement Interview";
    else if($purpose=='others')
        $purpose = "others";

    $reason = mysql_real_escape_string($_POST['reason']);

    $sql = "insert into video_conf_room(employee_id, emp_name, division, s_name, email, contact_no, intercom, from_time, to_time, b_f_time, b_t_time, purpose, reason) 
            values('$id','$name','$div','$school','$email','$contact','$intercom','$from','$to','$subfrom','$addto','$purpose','$reason')";

     $res = mysql_query($sql, $con) or die(mysql_error());
     if($res)
     {
        echo "you have successfully booked the video comferencing room";
        $message = "Following are the details for the video conferencing room registration booked recently \r\n Faculty id: ".$id."\r\nName: ".$name."\r\n Divison: "
                    .$div."\r\n School: ".$school."\r\n email: ".$email."\r\n Contact: ".$contact."\r\n Intercom no.: ".$intercom."\r\n Purpose: ".
                    $purpose."\r\n Reason: ".$reason."\r\n Booked from :".$subfrom."Booked till :".$addto;
        $message = wordwrap($message, 70, "\r\n");

        mail('mymail@domain.com','Video conferencing room registration',$message);


     }

您将运行如下查询

SELECT * FROM `video_conf_room` WHERE ('$from' BETWEEN `from_time` AND `to_time`) OR ('$to' BETWEEN `from_time` AND `to_time`)

。。。如果您得到任何结果,那么此时会预订另一个会议,而您不会插入预订。

您将运行如下查询

SELECT * FROM `video_conf_room` WHERE ('$from' BETWEEN `from_time` AND `to_time`) OR ('$to' BETWEEN `from_time` AND `to_time`)

。。。如果您得到任何结果,那么此时会预订另一个会议,而您不会插入预订。

当我试图在查询中实现这一点时,它总是显示日期和时间重叠$reason=mysql\u real\u escape\u字符串($\u POST['reason'])$sql1=“选择*从
视频会议室
其中('$FROM'介于
从时间
到时间
)或('$to'介于
从时间
到时间
)”$response=mysql\u query($sql1,$con)或die(mysql\u error());如果(!$response){//执行注册查询}否则回显“时间重叠”;'它总是显示“时间重叠”请告诉我,我应该做什么修改?当我试图在我的查询中实现这一点时,它总是显示日期时间重叠$reason=mysql\u real\u escape\u字符串($\u POST['reason'])$sql1=“选择*从
视频会议室
其中('$FROM'介于
从时间
到时间
)或('$to'介于
从时间
到时间
)”$response=mysql\u query($sql1,$con)或die(mysql\u error());如果(!$response){//执行注册查询}否则回显“时间重叠”;'它总是显示“时间重叠”请告诉我,我应该做什么修改?