Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

Availability across multiple hotels, room types, blackout dates, and reservations in SQL

0

44 views

How do you find availability across multiple hotels, room types, blackout dates, and reservations? A solution using MySQL (and PHP if necessary) is desired.

Input: #rooms required, #people per room, check in date, number of nights. Example: 2 rooms, 3 people per room, 4/14/2011, 3 nights

Output: will show hotel and room details if there is availability across the date range.

Sample tables:

Hotel_T
Hotel_ID
--------
Hotel_1


Room_Type_T
Room_Type | Hotel_ID | Capacity | Quantity
------------------------------------------
King      | Hotel_1  | 4        | 2


Reservation_T
Room_Type | Hotel_ID | Room_Quantity | #People | Check-In  | #Nights
--------------------------------------------------------------------
King      | Hotel_1  | 1             | 1       | 4/12/2011 | 3


Blackout_T 
Room_Type | Hotel_ID | Room_Quantity | Unavailability_Start_Date | #Nights
--------------------------------------------------------------------------
King      | Hotel_1  | 1             | 4/16/2011                 | 6

Notes: "Capacity" is the number of people that can fit in a room. Blackout_T are the dates and quantity of rooms not available by hotel and room type.

So for the first example of input "2 rooms, 3 people per room, 4/14/2011, 3 nights" no result is produced because both the Reservation_T and Blackout_T make only 1 room available during that date range. However, with input of "1 room, 3 people per room, 4/14/2011, 3 nights" would return Hotel_1, King.

I've come up with an ugly solution involving php looping over multiple queries, but I'm guessing there is a much more efficient way.

Thanks for your ideas in advance!

asked April 14, 2011 11:51 am CDT
Tom
posted via StackOverflow

1 Answer

0
 

You could take your PHP function and make it a stored procedure, which would make it run much faster, but you're not going to get what you want as a single SQL query.

answered April 14, 2011 12:23 pm CDT
Nik

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions