简体   繁体   English

mysql查询显示在线酒店预订中的剩余房间类型

[英]mysql query display remaining room type in an online hotel reservation

I'm working on this online reservation project and I am stock in this part. 我正在从事这个在线预订项目,这部分我有货。 Here's the scenario. 这是场景。 database structure: 数据库结构:

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

I can already get a good result from my query wherein I could scan all available rooms and display all my the information that I want. 我已经可以从查询中获得良好的结果,其中可以扫描所有可用的房间并显示我想要的所有信息。

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

What I need is to display all the remaining room_type that is available. 我需要显示所有可用的剩余room_type。 So for example if there are 5 standard room and 5 deluxe room and 1 standard room is occupied by guest1 from 2012-10-01 to 2012-10-05 and 1 deluxe room occupied at the same date by guest2 then the site will be still displaying standard and deluxe room since there are 4 left for each of the room_type. 因此,举例来说,如果从2012年10月1日到2012年10月5日guest1占用了5个标准房和5个豪华房,并且1个标准房被guest1占用,而guest2在同一日期占用了1个豪华房,那么该站点将仍然显示标准房和豪华房,因为每个room_type还剩4个。

Note that I will be putting the room_type in a html table and noOf_Rooms left in a combo box. 请注意,我将把room_type放在html表中,并将noOf_Rooms留在组合框中。

Please help been researching and reading a lot but still can't figure it out. 请帮助我们进行大量研究和阅读,但仍然无法弄清楚。 Thank you in advance for all your help. 预先感谢您的所有帮助。

Cheers 干杯

Extending your query: 扩展查询:

 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

I don't like that your room table contains the guest_id. 我不喜欢您的房间表包含guest_id。 Make something like a 'reservation' table that maps guests and rooms, and contains all the dates, etc. 进行类似于“预订”表的操作,该表可映射客人和房间并包含所有日期等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM