简体   繁体   English

MySQL查询事件的日历

[英]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数据表,如下所示:

  • ID ID
  • ID_USER ID_USER
  • BODY_NAME BODY_NAME
  • BODY_START BODY_START
  • BODY_END BODY_END
  • IS_DONE 已经完成了
  • TIME_CREATED TIME_CREATED
  • TIME_UPDATED TIME_UPDATED
  • TIME_DELETED TIME_DELETED

The BODY_START and BODY_END is using unix_timestamp. BODY_STARTBODY_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: 例:

  • ID f8a58d0c8280db2340863a1ac7aa60b0 编号f8a58d0c8280db2340863a1ac7aa60b0
  • ID_USER e576c22ce89f38ee422ec818807b99b8 ID_USER e576c22ce89f38ee422ec818807b99b8
  • BODY_NAME test_event BODY_NAME test_event
  • BODY_START 1422720000 BODY_START 1422720000
  • BODY_END 1428422400 BODY_END 1428422400
  • IS_DONE 0 IS_DONE 0
  • TIME_CREATED 1422845255 TIME_CREATED 1422845255
  • TIME_UPDATED 0 TIME_UPDATED 0
  • TIME_DELETED 0 TIME_DELETED 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM