重复活动

时间:2011-07-25 13:09:58

标签: php mysql

您好我一直在阅读许多反复出现的主题,但仍然没有关于如何在我的日历应用程序中实现此逻辑的想法。我有这张桌子:

id | title | start               | end                 | recurring
 1 | test1 | 2011-07-25 08:30:00 | 2011-07-25 10:30:00 |   day
 2 | test2 | 2011-07-26 08:30:00 | 2011-07-26 10:30:00 |   week
 3 | test3 | 2011-07-26 08:30:00 | 2011-07-26 10:30:00 |   month
 4 | test4 | 2011-07-26 08:30:00 | 2011-07-26 10:30:00 |   year

当用户查看日历时,我将参数发送到url以从数据库中获取数据。例如:

月视图: http://www.domain.com?start=2011-07-01&end=2011-07-31

周视图: http://www.domain.com?start=2011-07-25&end=2011-07-29

到目前为止我所拥有的是:

SELECT * CASE recurring WHEN "day" THEN IF(DATE_FORMAT(CURDATE(),"%j") = DATE_FORMAT(e.start,"%j"),1,0) WHEN "week" THEN IF(DATE_FORMAT(CURDATE(),"%w") = DATE_FORMAT(e.start,"%w"),1,0) END FROM event;

它只能检索一次......但如果我查看2011-08-01到2011-08-05下周的日历,它将无效。

我的问题是,如何根据网址参数检索重复发生的事件?非常感谢任何帮助和建议。

PS:我确实偶然发现了这个帖子:PHP 5.3 DateTime for recurring events它似乎接近我所需要的但只是在我的情况下我无法弄清楚如何用我的开始和结束日期时间动态地实现它。

2 个答案:

答案 0 :(得分:0)

去检查这个问题:How to calculate the difference between two dates using PHP?

只需计算GET ['start']和GET ['end']之间的差异,并将其“翻译”为'day','week','month'或'year'。

答案 1 :(得分:0)

这是一周,如果你将周改为每月等等,它会起作用

$sql = "Select form tablename where start > '".$_GET['start']."' and end = '".$_GET['end']."' where recurring = 'week'"

相关问题