在 PHP 日历上显示事件
我想问我的数据库中是否有一个事件表,例如
description | startdt | enddt
event1 | 2010-04-01 10:00:00 | 2010-04-01 13:00:00
event2 | 2010-04-09 14:00:00 | 2010-04-09 18:00:00
event3 | 2010-04-30 11:00:00 | 2010-05-02 16:00:00
我已经创建了一个php日历,我如何将上述事件显示到我的日历上,以便它看起来像谷歌日历?例如,对于 2010-04-01,它将在月历上显示“event1”。
谢谢。
I would like to ask if I have a table of events on my database, e.g.
description | startdt | enddt
event1 | 2010-04-01 10:00:00 | 2010-04-01 13:00:00
event2 | 2010-04-09 14:00:00 | 2010-04-09 18:00:00
event3 | 2010-04-30 11:00:00 | 2010-05-02 16:00:00
I have already created a php calendar, how can I display these above events onto my calendar, so that it will look something like the google calendar? e.g. on the for 2010-04-01, it will display "event1" on the month calendar.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您已经预先计算了 $year 和 $month 变量来显示日历网格,您可以从数据库中获取数据,如下所示:
然后在构建日历时,检查
中是否存在 $day $events
数组并按照您希望的方式输出描述:当然,如果您有跨越多天的事件,那么您必须修改一些内容来处理该问题,但这应该让您至少从单一开始 -日活动。
Assuming you've got a $year and $month variable already precomputed for displaying the calendar grid, you'd fetch the data from the database something like this:
Then while building the calendar, check if $day is present in the
$events
array and output the descriptions however you wish:Of course, if you have events that span multiple days, then you'll have to modify things to handle that, but this should get you started with at least single-day events.