Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用mysql和PHP对日历应用程序进行条件选择_Php_Mysql - Fatal编程技术网

使用mysql和PHP对日历应用程序进行条件选择

使用mysql和PHP对日历应用程序进行条件选择,php,mysql,Php,Mysql,我目前正在用php和mysql编程一个日历,在选择我想显示的所有事件时,我一直使用一些功能。我实现了重复事件的可能性。因此,我设置了事件开始的时间戳和确定事件何时结束的时间戳。此外,我还得到了一些整数值,它们代表了事件重复的节奏。 然后,我根据随请求发送的时间戳获取事件 现在,我希望用户能够将事件从周末转移到周末前的周五或周末后的周一。例如: From: 1450306800 (today) until: 0 (infinite) rythm : 1 (-> every month) j

我目前正在用php和mysql编程一个日历,在选择我想显示的所有事件时,我一直使用一些功能。我实现了重复事件的可能性。因此,我设置了事件开始的时间戳和确定事件何时结束的时间戳。此外,我还得到了一些整数值,它们代表了事件重复的节奏。 然后,我根据随请求发送的时间戳获取事件

现在,我希望用户能够将事件从周末转移到周末前的周五或周末后的周一。例如:

From: 1450306800 (today) 
until: 0 (infinite)
rythm : 1 (-> every month)
jump:2 (-> on every 2nd day / month)
weekends : 3 (-> shift to next monday)

-> January 2nd 2016 is a saturday and i want to display that event on the next monday.
当前,我的选择看起来是这样的:(:day->timestamp from request,:d->day of month from:day,:weekday->day of the week from:day)

从事件中选择*
其中repeat_from=:day)或(repeat_直到=0))
和案件周末
当0时,则(:1和7之间的工作日)
当1时,则(:工作日<6)
什么时候2那么??
什么时候3那么??
凯斯·瑞思
当1然后(:d-天(从UNIXTIME(重复从))/(跳转+1)=CEIL(:d-天(从UNIXTIME(重复从))/(跳转+1))。。。[所有其他案例]
如何检查事件是否在select中的星期六或星期日之前/之后显示?我能想到的唯一方法是或多或少地重复从“…和案例rythm…”部分中选择的全部内容,这部分内容相当多。
或者最好的方法是,如果事件发生变化,则在每周一/周五获取事件,然后使用php函数检查事件是否在周六或周日显示?

为什么不在php后端执行所有计算和匹配?在MySQL查询中有这么多的case和子句,执行起来可能会非常慢

根据您的主要标准选择所有事件。在您的情况下,这可能是:

SELECT * FROM 
    events 
WHERE 
    repeat_from <= :day AND
    (
        (repeat_until >= :day) OR 
        (repeat_until = 0)
    )

date()


如果您提供一些进一步的解释和/或示例,我将尝试更具体地介绍解决方案。干杯。

使用sql进行选择是否比只获取所有内容,然后用php转储其中一半更快?这基本上是我试图将其放入select语句而不是php中的过滤函数的唯一原因。@Lapskaus通常是的,但是日期函数(和许多其他内置MySQL函数一样)需要额外的时间和资源来进行必要的计算。实际上,您可以比较两者的响应时间,看看哪一个更适合您。但在原始查询中,不仅使用了日期函数,而且还设置了条件,这增加了延迟。
SELECT * FROM 
    events 
WHERE 
    repeat_from <= :day AND
    (
        (repeat_until >= :day) OR 
        (repeat_until = 0)
    )
# you can match the week number of different dates 
$currentWeekNumber = date('W');
$specificDayWeekNumber = date('W', strtotime($specificDate));

# or match the day number
$currentDayNumber = date('N');
$specificDayNumber = date('N', strtotime($specificDate));