0

I am designing a hotel booking system. My tables are as follow:

rooms:

id, room, room_type, hotel_id

room_type:

id, type, hotel_id

booking

id,room_id,type_id, hotel_id, checkin, checkout

I am trying to make a room availability form which checks the booking table and gets all the rooms under selected room type with the status i.e whether the room is available or not on the given dates.

Here are have three conditions to check:

checkin_date < booking table checking date

Or

checkin_date > booking table checkout date

Or

room_id (with hotel it and room type as specified) should not be available in booking table i.e it has never been booked.

Hence, I designed the following query but it failed:

SELECT * FROM rooms where room_type = '$room_types' & 'hotel_id' = '$hotel_ids' AND `id` IN (SELECT room_id FROM booking WHERE (`hotel_id`='$hotel_id' AND `room_type`='$room_types' AND ( `checkin` > '$checkout' OR `checkout` < '$checkin' ) ) ) or 'id' NOT IN (SELECT room_id FROM booking WHERE `hotel_id`='$hotel_id' AND `room_type`='$room_types' ) 

here

$checkin refers to checkin date selected by user.
$checkout refers to checkout date selected by user.
$hotel_id is hotel id.
$room_type is room type like deluxe etc.

Any advice on what is correct way of doing this?

GoSSDHosting
  • 89
  • 1
  • 11

0 Answers0