0

我创建了一个完美运行的日历,但是我需要能够插入运行多天的事件。日历显示单日上午和下午的事件,但是当输入多天的事件时,事件显示在事件开始日期和结束日期之间的日期。我使用时间戳作为开始和结束时间。这是我当前的 SQL:

$day_start = mktime(0, 0, 0, $cMonth, ($i - $startday + 1), $cYear);
$day_morning_end = mktime(11, 59, 59, $cMonth, ($i - $startday + 1), $cYear);
$day_afternoon_start = mktime(12, 0, 0, $cMonth, ($i - $startday + 1), $cYear);
$day_end = mktime(23, 59, 59, $cMonth, ($i - $startday + 1), $cYear);

$morn_sql = "SELECT * FROM tbl_events WHERE (start_stamp>='$day_start' AND end_stamp<='$day_morning_end') OR (start_stamp<'$day_start' AND end_stamp>'$day_end')";

下午还有一个查询。正如我所说,它工作正常,除了在事件开始和结束的那一天显示事件,但它在中间的几天显示。

谢谢

4

1 回答 1

0

这未经测试,因为我没有表格/数据,但我希望这会有所帮助。:)

    $day_sql = "SELECT * FROM tbl_events 
       WHERE start_stamp BETWEEN '$day_start' AND '$day_end' 
            AND end_stamp BETWEEN '$day_start' AND '$day_morning_end'
                OR end_stamp BETWEEN '$day_afternoon_start' AND '$day_end'";              
于 2012-04-30T10:05:10.967 回答