PHP日历多日活动

时间:2012-04-30 09:35:00

标签: php events calendar

我创建了一个完美运行的日历,但是我需要能够插入多天运行的事件。日历显示单日AM和PM的事件,但在多天输入事件时,事件显示在事件开始日期和结束日期之间的日期。我正在使用时间戳作为开始和结束时间。这是我当前的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')";

下午还有另一个查询。正如我所说的那样,除了在开始和结束的那天显示事件之外,它的工作正常,但是它显示在两者之间的日子。

由于

1 个答案:

答案 0 :(得分: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'";