I have a table in mysql that holds a start and end date. These start and end date are for when a hotel is booked. What I need to do is show a calendar that shows the dates that are booked and the dates that are available for the current month. How would I find out what days are booked for the current month? I could loop through each day of the current month but that would mean 30 or 31 queries, is there a better, more optimized way to find out what days are booked for the month so I can color code the days on a calendar?
The table structure is this:
hotelid int(11)
startdate (date)
enddate (date)
Query Request:
SELECT * FROM hotel_book WHERE hotelid = 1 AND DATE_FORMAT(startdate,'%Y-%m') >= '2012-08' AND DATE_FORMAT(enddate,'%Y-%m') <= '2012-08'
Im sure I could just pass it 2012-08-01 and 2012-08-31 so Im not processing the date format on each check. But just for example purposes.
Another approach to this would be to allow your calendar to accept start and end dates and render each day that is booked within the calendar logic. If the calendar uses javascript rather than PHP or MySQL impact on your server(s) would be minimal. Either way you end up looping, it just depends on where you want that to happen.