使用这些桌子阻塞房间
Posted
技术标签:
【中文标题】使用这些桌子阻塞房间【英文标题】:Room blocking using these table 【发布时间】:2016-02-10 14:38:54 【问题描述】:我有以下这些数据库表
预订表
.---------------+-----------------+------------------+---------------.
| reservationID | guestID | check_in | check_out |
+---------------+-----------------+------------------+---------------+
| 1 | 1 | 2016-02-13 | 2016-02-14 |
| 2 | 1 | 2016-02-16 | 2016-02-19 |
.---------------+-----------------+------------------+---------------.
房间预订表
.---------------+-----------------+------------------+---------------+--------------.
| roomReserveID | reservationID | date_scheduled | roomDetailsNo | roomNo |
+---------------+-----------------+------------------+---------------+--------------+
| 1 | 1 | 2016-02-13 | 2 | 101 |
| 2 | 1 | 2016-02-13 | 2 | 101 |
| 3 | 4 | 2016-02-16 | 6 | 116 |
| 4 | 4 | 2016-02-17 | 6 | 116 |
| 5 | 4 | 2016-02-18 | 6 | 116 |
| 6 | 4 | 2016-02-19 | 6 | 116 |
.---------------+-----------------+------------------+---------------+--------------.
房间数
.---------+-----------------+-----------.
| RoomID | RoomDetailsNo |room_status|
+---------+-----------------+-----------+
| 101 | 1 | reserved |
| 102 | 3 | available |
| 103 | 3 | available |
| 104 | 2 | reserved |
| 105 | 2 | available |
| 116 | 6 | reserved |
.---------+-----------------+-----------.
房间详情表
.----------------+----------------+---------.
| RoomDetailsNo | room_type |room_rate|
+----------------+----------------+---------+
| 1 | Standard Room | 3000 |
| 2 | Deluxe Room | 3500 |
| 3 | Family Room | 4000 |
| 4 | Standard Quad | 4000 |
| 5 | Deluxe Quad | 4000 |
| 6 | Dormitory Room | 4000 |
.----------------+----------------+---------.
在下面我有当前查询,我正在使用它来阻止 2016-02-13 到 2016-02-14 的房间 101 和 2016-02-16 到 2016-02-19 的房间 116。
$roomBlock = mysqli_query($conn, "
SELECT COUNT(r.roomDetailsNo) AS available_rooms, rd.roomDetailsNo, rd.room_type, rd.room_rate,
r.room_status, rd.room_pax, rd.max_cap, rd.inclusive, rd.description, rd.image_name
FROM rooms AS r
LEFT JOIN roomdetails AS rd
ON r.roomDetailsNo = rd.roomDetailsNo
WHERE r.roomNo = (SELECT rr.roomNo
FROM roomreservation AS rr
WHERE rr.date_scheduled NOT BETWEEN '$newCheckIn' AND '$newCheckOut')
GROUP BY room_type;
") OR die("Error in roomBlocking:".mysqli_error($conn));
变量 $newCheckIn 和 $newCheckOut 来自用户,它们是他们想要的入住和退房日期。如何不显示在特定日期预订的房间?
当我尝试这个查询时,结果是: roomBlocking 中的错误:子查询返回超过 1 行
【问题讨论】:
正如错误所说 - 您试图在只允许返回 ONE 值但子查询返回 MULTIPLE 行的上下文中使用子查询。换句话说,不要使用=
,使用IN
那么删除日期内不可用房间的正确查询应该是什么?
【参考方案1】:
您的子查询返回超过 1 个预期结果,因此您应该使用 where r.roomNo in, instesd of where r.roomNo =
【讨论】:
以上是关于使用这些桌子阻塞房间的主要内容,如果未能解决你的问题,请参考以下文章