tags:

views:

228

answers:

2

Hey Guys,

I'm creating a scheduling system for my school that allows teachers to book rooms/vehicles. I'm just stuck on one aspect: populating the calendar. Basically, it'll have a month and week view. The monthly view I'm fine coding, but it's the weekly view I'm stuck on.

The people that are inserting bookings will be able to specify the date of the booking, and the block(s) of the day that it takes up. I could recurse through the days/blocks in the week, running queries on those days and seeing if something is booked at that time, but that would be WAY too inefficient.

My second idea was to get a timestamp for the first and last days of the week and then populate an associative array with all of those dates. Then I could recurse through the blocks of all the days and find any matches in the array. That's a bit better, but it still seems to inefficient for me.

Is there a better way of doing this?

+1  A: 

Select all the events which occur on dates on or between the start and end of the active week, put the results in an array, then loop through the days in the week and check whether events in the array take place on the active day.

Jonathan Patt
Yeah, that's one of the options I had put in the question. Is it going to be efficient enough though? It'll have quite a few users using it at any one time.
BraedenP
It probably will be efficient enough since both your dataset and the amount of time you're looping over are fairly small.Caching/generating the content statically on every update to the schedule is probably a much better option for you than code micro-optimizations.
AvatarKava
+1  A: 

You can use quick calendar, its very simple, you just need to pass SQL query to that, it will work as it is expected.

check this tutorial

http://www.evolt.org/quick%5Fcalendar%5Fusing%5Fajax%5Fand%5Fphp

santosh
They ended up needing some more custom functions within the calendar, but I used the math on that site as a basis for calculating starting days, etc. Thanks a lot!
BraedenP