开发者

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

开发者 https://www.devze.com 2023-02-14 03:22 出处:网络
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.

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.

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.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 - Satur开发者_运维问答day: 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.

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).

When you want to fetch the show, a simple JOIN will give you the times you want.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消