I am currently making a website for an online radio station. I am trying to find a way to have what program is currently on, which changes dynamically, depending on the time. Eg:
I’m guessing i need to use PHP, but am really not sure even where to begin. Can anyone help?
Probably the best solution would be PHP and a fairly simple database
My thought would be to create a database like this:
ok, now say you’ve got show X that’s on from 9am to 11am on Monday, Wednesday and Friday… you’d create a record in the show info table with the name/info of that show, it’s start time and end time… In the SHOW_DAYS table, we’ll assume day ids are 1-7 for Sunday – Saturday…
If show X has an id of 1, then the entries to the SHOW_DAYS table would be 2,1 4,1 6,1 That’s show id 1 on days 2,4, and 6 (mon, wed, and fri)… Suppose this same show has a different time slot on a different day of the week, well with this database model you’d have to create a different entry in the SHOW_INFO table.. there are more streamlined ways to handle it, but since there isn’t likely to be an outrageous number of shows to deal with, it’s probably not a huge deal.
ok, then your php script on the page would check what the current time is (on the server) and what day of the week it is, then run a query against the database to pull the show name where the start time is < the current time, and end time is > the the current time, and the show ID is within the list of show ids matching the days in the SHOW_DAYS table..
the sql would look something like this:
That will return just the show name of the show currently on the air. If you wanted it to return the times as well, then you’d have to add those to the select statement, as such:
The php code could basically be something along these lines:
Of course you would also need to add the code to open a connection to the database, issue the select statement, and print the output, but that’s all pretty standard stuff that can be found easily by looking through the online manual at php.net… I’ve covered all the difficult bits here for you. ;)
There’s a couple other benefits afforded by going to this length to handle the stuff you’re after…
Of course this is a very basic implementation of what you’re after, it could be expanded greatly to handle seasonal programs, etc.. this could also be tied in to a program archive… the limits are really only determined by how far you want to expand it….
Hope that helps
This reply has been reported for inappropriate content.
Check out #7 in this article:
http://nettuts.com/html-css-techniques/ … echniques/
Without modification to handle adjustment for visitor timezones that would only be accurate for people in the same timezone as the radio station.. most likely those are the only people listening to the station anyway, but there’s not sense is putting out a website that’s broken for everyone else on the web. ;)
You must be logged in to reply to this topic.