我正在进行这个在线预订项目,我在这部分库存。这是场景。 数据库结构:
tbl_guestinfo
guest_id
name
checkin
checkout
numAdults
numChild
tbl_rooms
room_id
room_name
guest_id
type_id
tbl_roomtype
type_id
room_rate
room_type
noOf_Rooms
我已经可以从我的查询中获得一个好结果,我可以扫描所有可用的房间并显示我想要的所有信息。
SELECT *
FROM tbl_rooms, tbl_roomtype
WHERE guest_id NOT IN
(
SELECT `guest_id` from tbl_guestinfo where
(`checkin` < ' $varCheckOut' and `checkout`>= '$varCheckOut' )
OR (`checkin`<= '$varCheckIn' and `checkout`> '$varCheckIn' )
OR (`checkin`>= '$varCheckIn' and `checkout`<='$varCheckOut')
)
我需要的是显示所有剩余的room_type。例如,如果在2012-10-01至2012-10-05期间有1个标准房和5个豪华房以及1个标准房被guest1占用,并且1个豪华房在同一天被guest2占用,那么该网站将仍然是显示标准和豪华房间,因为每个房间类型都有4个。
请注意,我将把room_type放在一个html表中,并将noOf_Rooms放在一个组合框中。
请帮助研究和阅读很多,但仍然无法弄明白。提前感谢您的帮助。
干杯
答案 0 :(得分:0)
扩展您的查询:
SELECT room_type, count(*)
FROM tbl_rooms, tbl_roomtype
WHERE guest_id NOT IN
(
SELECT `guest_id` from tbl_guestinfo where
(`checkin` < ' $varCheckOut' and `checkout`>= '$varCheckOut' )
OR (`checkin`<= '$varCheckIn' and `checkout`> '$varCheckIn' )
OR (`checkin`>= '$varCheckIn' and `checkout`<='$varCheckOut')
)
GROUP by room_type
我不喜欢你的房间表包含guest_id。制作类似“预订”表格的地图,用于映射客人和房间,并包含所有日期等。