房间可用性检查SQL查询

时间:2017-09-26 14:12:49

标签: php sql checkin

我正在设计酒店预订系统。我的表格如下:

房间:

id, room, room_type, hotel_id

room_type:

id, type, hotel_id

预订

id,room_id,type_id, hotel_id, checkin, checkout

我正在尝试制作一个房间可用表格,检查预订表并获取所选房间类型下的所有房间的状态,即房间是否在指定日期可用。

这里有三个要检查的条件:

checkin_date < booking table checking date

或者

checkin_date > booking table checkout date

或者

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

因此,我设计了以下查询,但失败了:

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' ) 

这里

$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.

有关正确方法的建议吗?

0 个答案:

没有答案