我想看看我从数据库读取的时间是否与用户提供的时间重叠。
我的数据库如下所示:
-----------------------------------------------
|organiser|meeting_start|meeting_end|boardroom|
-----------------------------------------------
| John Doe| 1340193600 | 1340195400| big |
-----------------------------------------------
我的代码如下所示:
date_default_timezone_set('Africa/Johannesburg');
$from = strtotime($_GET['meeting_date'] . ' ' . $_GET['meeting_start']);
$to = strtotime($_GET['meeting_date'] . ' ' . $_GET['meeting_end']);
$another_meeting = false;
$meeting_date = strtotime($_GET['meeting_date']);
$meeting_next = $meeting_date + 86400;
$result = mysql_query("SELECT meeting_start, meeting_end FROM admin_boardroom_booking WHERE boardroom = '" . $_GET['boardroom'] . "' AND meeting_start >= '" . $meeting_date . "' AND meeting_end < '" . $meeting_next . "'")or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$from_compare = $row['meeting_start'];
$to_compare = $row['meeting_end'];
$intersect = min($to, $to_compare) - max($from, $from_compare);
if ( $intersect < 0 )
$intersect = 0;
$overlap = $intersect / 3600;
if ( $overlap <= 0 ) {
$another_meeting = true;
break;
}
}
if ($another_meeting)
echo 'ERROR';
如果我故意键入两个重叠时间,它不会回显错误。我究竟做错了什么?