php shedule help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dfrance
Forum Newbie
Posts: 1
Joined: Sat May 02, 2009 8:34 am

php shedule help

Post by dfrance »

Hi I have a weekly shedule that I have put into a table using a mysql database, I need a way of producing the event for the given day and time that I visit my shedule, so say I visit my online shedule on tuesday @ 15:45 I need it to produce the events for the 2 hour window on the given day e.g. 14:00 - 15:59.

So basically I need it to select a certain row in a table at the current time and day.

so here is how my shedule is setup

Days Monday/Tuesday/Wednesday/Thursday/Friday/Saturday/Sunday

Times
08:00 - 09:59
10:00 - 11:59
12:00 - 13:59
14:00 - 15:59
16:00 - 17:59
18:00 - 19:59
20:00 - 21:59
22:00 - 23:59
00:00 - 07:59

Not asking for a complete script here just some pointers in the right direction.

Regards, Dom.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: php shedule help

Post by Apollo »

Simply identify each event with its starting and ending timestamp, using a default unix timestamp (seconds since 1970). You can then do

Code: Select all

SELECT * FROM table WHERE startTime<=$curTime AND endTime>$curTime
to select the row for the current time (with $curTime being the current time).

As long as you're working with 2 hour windows, you can use endTime = startTime+2*60*60 when creating new rows/events.

See also date and mktime.
Post Reply