在 PHP/MySQL 中创建定期日历事件

发布于 2024-12-03 05:32:02 字数 80 浏览 0 评论 0原文

我正在尝试创建一个包含重复事件(例如每周或每月)的事件日历,但我无法理解它。有人能给我一些指点吗?这样做的最佳方法是什么?非常感谢任何帮助。谢谢。

I am trying to create an event calendar with recurring events (ex. weekly or monthly) but I cannot wrap my head around it. Can anyone give me some pointers? What is the best way to go about doing this? Any help is greatly appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月流歌 2024-12-10 05:32:02

创建三个表,其结构如下:

event

-id
-schedule_type
-schedule_id
-title
etc.

schedule

-id
-event_id
-datetime

schedule_recurring

-id
-event_id
-date
-time

event 表中,schedule_type 字段将为 0 或 1,这将向应用程序指示调度信息存储在哪个表中,以及如何解释该信息。

非重复事件将存储在 schedule 中,日期时间:2011-09-06 00:00:00,重复事件将存储在 schedule_recurring 中,日期时间为:2011-09-06 00:00:00 :“每个第一个星期一”,时间:09:30,12:20(如果该事件在该月的每个第一个星期一发生两次)。

也许这会帮助您入门!

Create three tables with a structure like:

event table

-id
-schedule_type
-schedule_id
-title
etc.

schedule table

-id
-event_id
-datetime

schedule_recurring table

-id
-event_id
-date
-time

In your event table, the schedule_type field will be either 0 or 1, which would indicate to the application which table the scheduling information is stored in, as well as how to interpret that information.

A non-recurring event will be stored in schedule with a datetime: 2011-09-06 00:00:00, and recurring events will be stored in schedule_recurring with a date: 'every 1st Monday' and a time: 09:30,12:20 (If the event occurs twice on every first Monday of the month).

Maybe this will help get you started!

谈场末日恋爱 2024-12-10 05:32:02

我知道这是一篇旧文章,但我也在想同样的事情。

我喜欢这个人的解决方案,即使用多个表来完成此操作,但实际上这一切都可以从一张表中完成。

创建一个包含以下数据的表...

event_title
event_text
event_image
and_other_fields_about_event
recur_code (text)
recur_mode (integer)
start_date (date)
end_date (date)
recur_end_date (date)

recur_mode 可以有三种状态 -
0 = 没有复发
1 = 有结束日期的重复
2 = 正在进行,没有结束日期(例如,如果您想添加诸如 1 月 1 日之类的内容作为新年),

如果日期重复出现,则 recur_code 将在其中存储 NULL 或代码。应该使用的代码是 PHP DateInterval 代码(即 P1Y 为 1 年或 P3M(3 个月)或 P7D(7 天)等) - 如果您想稍微缩小数据,您可以砍掉初始值'P' 并稍后将其添加回来,因为最初的 'P' 始终是 P,它代表周期,因此“周期 3 个月”“周期 7 天”等。

然后当您从数据库 - 您通过以下搜索检索所有数据

( end_date >= CURDATE () ) OR ( ( recur_mode = 1 ) AND ( recur_end_date >= CURDATE () ) ) OR ( recur_mode = 2 )

(请注意,这不是正确的 SQL - 这只是您需要的 or 语句的基本示例)

,然后一旦您检索到数据,就使用带有 while 循环和 DateInterval 的 PHP增加 start_date 直到下一次重新发生,同时确保如果 recur_mode 设置为 1,则开始日期不晚于 recur_end_date。

所有这些都在一个表中完成 - 而且如果您想要一个输入表单来放入代码,然后使用带有日期间隔值的隐藏字段,同时使用各种单选按钮选择间隔 - 然后使用 jQuery onchange 来更新隐藏值新的选择器值。

I know this is an old post but I was thinking the same thing too.

I like the persons solution about using multiple tables to do it, but in fact it can all be done from one table.

Create a table with the following data...

event_title
event_text
event_image
and_other_fields_about_event
recur_code (text)
recur_mode (integer)
start_date (date)
end_date (date)
recur_end_date (date)

recur_mode can have three states -
0 = no recurrence
1 = recurrence with end date
2 = ongoing with no end date (e.g. if you want to add something like 1st Jan as New Years Day)

recur_code would store either NULL or a code in it if the date recurs. The code that should be used there would be the PHP DateInterval code (i.e. P1Y for 1 year or P3M (3 months) or P7D (7 days), etc) - if you want to shrink the data a bit you could chop off the initial 'P' and add it back later as the initial 'P' is always going to be P, it stands for Period so "Period 3 Months" "Period 7 Days", etc.

Then when your retrieving data from the database - you retrieve all data with the following searches

( end_date >= CURDATE () ) OR ( ( recur_mode = 1 ) AND ( recur_end_date >= CURDATE () ) ) OR ( recur_mode = 2 )

(please note this isn't proper SQL - it's just a basic example of the or statement you'd need)

then once you've retrieved the data use PHP with a while loop and DateInterval to increase the start_date until you get to the next re-occurrence also making sure that if recur_mode is set to 1 the start date is not after the recur_end_date.

All done in one table - and also if you want an input form to put the code in then use a hidden field with the dateinterval value in whilst using various radio buttons to select the interval - then use jQuery onchange to update the hidden value with the new selector values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文