[英]MySQL query the events for a calendar
I'm building a SaaS calendar with MySQL & PHP. 我正在使用MySQL和PHP构建SaaS日历。
The front-end javascript calendar lib is fullcalendar(monthly view) http://fullcalendar.io/ 前端javascript日历库为fullcalendar(每月视图) http://fullcalendar.io/
I have a mysql data table named events
like this: 我有一个名为
events
的mysql数据表,如下所示:
The BODY_START
and BODY_END
is using unix_timestamp. BODY_START
和BODY_END
使用的是unix_timestamp。
Then in my PHP code, I built a query helper that generate a SQL like: 然后,在我的PHP代码中,我构建了一个查询助手,该助手生成一个SQL,例如:
"SELECT * FROM `" . $this->_tableName . "` WHERE `ID_ACCOUNT` = '$_id_account' AND (( `BODY_START` >= 1424649600 AND `BODY_START` <= 1428278400 ) OR (`BODY_END` >= 1424649600 AND `BODY_END` <= 1428278400))";
The start and end timestamp params provided by the fullcalendar. fullcalendar提供的开始和结束时间戳参数。
There is a question: 有一个问题:
if the event is crossing the current month, it will not be shown. 如果事件跨越当前月份,则不会显示。
example: 例:
f8a58d0c8280db2340863a1ac7aa60b0
f8a58d0c8280db2340863a1ac7aa60b0
e576c22ce89f38ee422ec818807b99b8
e576c22ce89f38ee422ec818807b99b8
test_event
test_event
1422720000
1422720000
1428422400
1428422400
0
0
1422845255
1422845255
0
0
0
0
If you do the query, this event will not show. 如果执行查询,则不会显示此事件。
how can i fix this? 我怎样才能解决这个问题? Thanks.
谢谢。
If I understand you correctly, simplify your query to be (in pseudo code): 如果我对您的理解正确,请将查询简化为(使用伪代码):
BODY_START <= month_end and BODY_END >= month_start
Your original query query above requires that events must either start or end during the month, but that's not actually what you want - you want any event that exists for any part of the month. 您上面的原始查询查询要求事件必须在一个月内开始或结束,但这实际上并不是您想要的-您希望该月任何部分都存在任何事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.