简体   繁体   English

如何在在线电台项目的数据库中存储日期和时间?

[英]How to store day and time in database for online radio station project?

I have started creating a website for a new online radio station, launching later in the year, and so far the basics are going well - it's running on Apache 2.2, with PHP 5.28. 我已经开始为新的在线广播电台创建一个网站,并于今年晚些时候启动,到目前为止,一切进展顺利-它运行在Apache 2.2和PHP 5.28上。

However, I have one problem I'm struggling to find a solution for - how to store day and time in the database my site runs on, not date and time. 但是,我有一个问题正在努力寻找解决方案-如何将日期和时间存储在我的网站运行所在的数据库中, 而不是日期和时间。

This is the type of thing I mean: 这是我指的类型:

http://www.metroradio.co.uk/staff.asp http://www.metroradio.co.uk/staff.asp

http://www.radioaire.co.uk/showdj.asp?DJID=41140 http://www.radioaire.co.uk/showdj.asp?DJID=41140

Notice in the second example how the date and time is shown: 注意在第二个示例中如何显示日期和时间:

This is my example: 这是我的示例:

Monday: 2:00 PM - 6:00 PM
Tuesday, Thursday - Saturday: 10:00 AM - 2:00 PM
Sunday: 7:00 PM - 11:00 PM

Although the links above use ASP.NET and IIS, my site uses PHP, and I'm not sure of the best way to get this to work in PHP. 尽管上面的链接使用ASP.NET和IIS,但我的网站使用的是PHP,但我不确定使它在PHP中运行的最佳方法。

This is my database structure for the presenter pages: 这是我的演示者页面的数据库结构:

presenterid - autoincrement, INT 11
presentername - varchar, 255
airtime - DATETIME
showdesc - varchar 255

Anyone got a good solution? 任何人都有一个好的解决方案?

thanx 谢谢

You could create a second table, with the following fields : 您可以使用以下字段创建第二个表:

show_id INT (foreign key)
day_id INT (use date('w'), date('S') or your own system)
begin TIME (time at which the show begins)
end TIME (time at which the show ends)

You must also add an unique constraint for the couple (show_id,day_id) . 您还必须为夫妇添加唯一约束(show_id,day_id)

When you want to fetch the show, a simple JOIN will give you the times you want. 当您想获取节目时,简单的JOIN将为您提供所需的时间。

You could have a program table (presenter, description, etc.), having a one-to-many relationship to a schedule table (day, start time, end time). 您可能有一个节目表(演示者,描述等),与时间表表具有一对多关系(日期,开始时间,结束时间)。

Then, you just have to query for all the schedules of a given program, ordered by day, and detect similar start/end times for consecutive days to present them on one line. 然后,您只需要查询给定程序的所有时间表(按天排序),并连续两天检测相似的开始/结束时间,即可将它们显示在一行上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM