[英]how to show not available rooms in my table
This is my query: 这是我的查询:
$result = mysql_query("
Select count(RoomType) AS Available_Rooms, RoomType, RoomRate
FROM tb_rooms
WHERE RoomNumber NOT IN (Select tb_roomsreserved.RoomNumber
From tb_roomsreserved
LEFT JOIN tb_reserved on tb_roomsreserved.reserved_id = tb_reserved.reserved_id
WHERE $arrival < tb_reserved.Departure AND $departure >tb_reserved.Arrival
UNION Select tb_roomsguest.RoomNumber From tb_roomsguest
LEFT JOIN tb_guest on tb_roomsguest.id = tb_guest.id
WHERE $arrival < tb_guest.Departure AND $departure >tb_guest.Arrival
AND tb_guest.Status = 'Approved'
UNION Select tb_roomscheckin.RoomNumber From tb_roomscheckin
LEFT JOIN tb_checkin on tb_roomscheckin.checkin_id = tb_checkin.checkin_id
WHERE $arrival < tb_checkin.Departure AND $departure >tb_checkin.Arrival
)
GROUP BY RoomType") or die (mysql_error());
This is my table: 这是我的桌子:
echo '<table style = "margin-bottom: 2.5%;" width = "90%">';
while($row = mysql_fetch_array($result)){
echo '<tr><td align = "center">';
echo $row['Available_Rooms'];
echo '</td><td align = "center">';
echo $row['RoomType'];
echo '</td><td align = "center">';
echo 'Available';
echo '</td></tr>';
}
echo '</table>';
How can I echo those rooms that are not available? 我该如何回应那些没有空位的房间? My query show only rooms which are available.
我的查询仅显示可用的房间。
Normally my table looks like this when all rooms are available. 通常,当所有房间都可用时,我的桌子看起来像这样。
Available_Rooms RoomType Availability
5 AtticRoom Available
4 Deluxe Available
4 FamilyRoom Available
13 StandardRoom Available
But when Deluxe And Family Rooms Hits 0 available rooms. 但是,当“豪华家庭房”达到0个可用房间时。 The outputs are these on.
输出是这些。
Available_Rooms RoomType Availability
5 AtticRoom Available
13 StandardRoom Available
I have been thinking on how can I do that. 我一直在思考如何做到这一点。
i ended up having this output. 我最终有这个输出。
Available_Rooms RoomType RoomRate
5 AtticRoom 2000
13 StandardRoom 2500
my tb_rooms contains 我的tb_rooms包含
RoomNumber RoomType RoomRate
201 FamilyRoom 3500
202 StandardRoom 2500
203 StandardRoom 2500
204 StandardRoom 2500
205 StandardRoom 2500
206 StandardRoom 2500
207 StandardRoom 2500
208 StandardRoom 2500
209 StandardRoom 2500
210 StandardRoom 2500
211 Deluxe 2300
212 FamilyRoom 3500
214 Deluxe 2300
301 FamilyRoom 3500
302 FamilyRoom 3500
303 StandardRoom 2500
304 StandardRoom 2500
305 StandardRoom 2500
306 StandardRoom 2500
307 StandardRoom 2500
308 Deluxe 2300
309 Deluxe 2300
401 AtticRoom 2000
402 AtticRoom 2000
403 AtticRoom 2000
404 AtticRoom 2000
405 AtticRoom 2000
Use the below query 使用以下查询
$result = mysql_query("Select (CASE WHEN count(RoomType) > 0 THEN count(RoomType) ELSE 0 END) AS Available_Rooms, RoomType, RoomRate
FROM tb_rooms
WHERE RoomNumber NOT IN (
Select tb_roomsreserved.RoomNumber
FROM tb_roomsreserved
LEFT JOIN tb_reserved on tb_roomsreserved.reserved_id = tb_reserved.reserved_id
WHERE $arrival < tb_reserved.Departure AND $departure >tb_reserved.Arrival
UNION Select tb_roomsguest.RoomNumber
FROM tb_roomsguest
LEFT JOIN tb_guest on tb_roomsguest.id = tb_guest.id
WHERE $arrival < tb_guest.Departure AND $departure >tb_guest.Arrival AND tb_guest.Status = 'Approved'
UNION Select tb_roomscheckin.RoomNumber
FROM tb_roomscheckin
LEFT JOIN tb_checkin on tb_roomscheckin.checkin_id = tb_checkin.checkin_id
WHERE $arrival < tb_checkin.Departure AND $departure >tb_checkin.Arrival
)
GROUP BY RoomType") or die (mysql_error());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.