我正在为我的项目开发类似日历的功能。
我有如下表格:
ID | Title |Where |tri| Start | End | tro
______________________________________________________________________
"4"|"Planingfrenzy" |"Street 8"|"0"|"1395835200"|"1395846000"|"1"
"5"|"Other meeting" |"Road 8" |"0"|"1395140400"|"1395158400"|"1"
"6"|"Third meeting" |"Lane 8" |"0"|"1395819000"|"1395824400"|"1"
"8"|"Weekend at cyprus"|"Cyprus" |"0"|"1395928800"|"1396162800"|"1"
我在选择一天内发生的所有事件时遇到问题。 我尝试了以下两个查询,但它们只返回那些在同一天开始和结束的事件。
/*
Start is a unixtimestamp for the beginning of the day
End is a unixtimestamp for the end of the day
*/
//This Returns to many events since all events that ends before the end timestamp is a match etc.
SELECT * FROM events WHERE (start > ? OR end<?)
//This matches all events that start and end at the same day. But a multi day event like "Weekend at cyprus" isn't returned since it is out of range
SELECT * FROM events WHERE (start > ? AND end<?)
如果开始/结束范围“触及”查询的时间戳范围,MySQL 或 PHP 是否有某种方法可以匹配?
最佳答案
假设?
的两个值是当天最早和最新的值,我想你想要:
where start < (?end) and end > (?start)
也就是说,当一个开始在另一个结束之前时存在重叠,反之亦然。
在这个答案中,(?end)
是当天的最后一个时间戳,(?start)
是第一个。
关于php - 选择 MySQL 范围内的所有时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22640293/