我正在建立一个在线酒店预订系统....使用php和mysql ....用户可以搜索和预订特定位置的酒店..搜索条件将是
1.城市或国家
2.签入和签出日期
3.嘉宾人数
我的sql架构如下....
表:酒店
hotel_id
hotel_name
country_id
city_id
表:房间
room_id
hotel_id
room_name
room_price
max_guests_allowed
no_total_rooms
no_booked_rooms
表:预订
reservation_id
room_id
hotel_id
check_in_date
check_out_date
查询在两个给定日期之间免费获得房间,并且可以容纳等于或大于否的人。用户给予的人:
SELECT rooms.room_id,
rooms.room_name,
rooms.max_guests_allowed,
rooms.room_price,
hotels.hotel_id,
hotels.hotel_name
FROM hotel,rooms
WHERE rooms.id NOT IN (SELECT room_id
FROM reservations
WHERE check_in_date < '$arrivalDate'
AND check_out_date > '$leaveDate')
AND rooms.max_guests_allowed >= '$no_of_guests';
现在......我必须显示结果......
1. Hotel 1
Room 1 No. of Rooms Free Price Max. Guests Allowed
Room 2 No. of Rooms Free Price Max. Guests Allowed
Room 3 No. of Rooms Free Price Max. Guests Allowed
2. Hotel 2
Room 1 No. of Rooms Free Price Max. Guests Allowed
Room 2 No. of Rooms Free Price Max. Guests Allowed
Room 3 No. of Rooms Free Price Max. Guests Allowed
etc.. etc...
如何修改我的查询以将酒店下面的房间分组,就像我上面提到的那样...... ???? 非常感谢提前....
答案 0 :(得分:1)
我可能会稍微误解问题/查询,但是你不能添加:
ORDER BY hotels.hotel_name ASC,rooms.room_name ASC
到查询结尾,在酒店和房间订单中给你结果?
编辑以原始格式显示,您可以使用与此类似的代码。我已经在PHP中完成了这项工作,因为您没有指定您正在使用的语言:
$currentHotel = -1;
while ($row = mysql_fetch_array())
{
if ($row["hotel_id"] != $currentHotel)
{
print "Hotel " . $row["hotel_id"] . "\n";
$currentHotel = $row["hotel_id"];
}
// print your room details out here
print "Room " . $row["room_name"];
// ...
}