使用 PHP/MySQL 调度脚本 - 逻辑帮助
我正在开发一个小脚本,用户可以在其中插入他们的“时间表”。但是,我需要一些帮助来确定如何创建数据库结构以及如何在数据库中输入事件“时间”的逻辑。
然而,需要注意的一件事是,当用户输入“时间表”时,他们不会输入确切的日期。相反,他们将进入“一周中的几天”。有点像“定期”约会。
例如,用户 A 可以输入以下时间表:
MWF - 上午 8:00 - 上午 10:00 MW - 2:00pm - 3:00pm 等等...
正如您所看到的,我正在寻找一种使用通用“一周中的日子”的方法,而不一定是确切的日期。
考虑到这一点,将其存储在数据库中的最佳方式是什么,因为我知道最终我可能会“查询”数据库以搜索可用时间。
我应该以毫秒或秒为单位输入它们吗? “0”表示周日中午 12:00?
任何建议都会很棒。
谢谢!
I'm looking to develop a small script where users can insert their "schedule." However, I need some help determining the logic of how to create the DB structure and how to input the "time" of the events in the database.
One thing to note, however, is that when users enter their "schedule", they will not be entering exact dates. Instead, they will be entering 'days of the week.' Somewhat like a 'recurring' appointment.
For example, User A could enter the following time schedule:
MWF - 8:00am - 10:00am
MW - 2:00pm - 3:00pm
etc...
As you can see, I'm looking for a way to use generic 'days of the week', not necessarily exact dates.
With this in mind, what would be the best way to store this in the database, knowing that eventually, I may be "querying" the database to search for available times.
Should I enter them in milliseconds or seconds? With "0" being 12:00AM on Sunday?
Any suggestions would be great.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,MySQL包含一个时间数据类型。我强烈建议您利用它。
无论如何,对于您的表格(这是用于学术安排,但相同的基本思想适用):
现在,您需要做的就是查看某人在周一 1 点到 2 点之间是否有空:
替换
$ mytime
与您在那里查看的任何时间。First of all, MySQL includes a time data type. I highly recommend you take advantage of it.
Anyway, for your tables (this is for an acadmic scheduling, but the same basic ideas apply):
Now, all you'd need to do to see if somebody's available on a Monday between 1 and 2 is:
Replace the
$mytime
with whatever time you're checking there.