-
Notifications
You must be signed in to change notification settings - Fork 0
/
rooms-available.sql
55 lines (55 loc) · 2.29 KB
/
rooms-available.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?
if ($room_type == "Not known") {
$where="WHERE ";
$where2="OR reservations.arrivalDate IS NULL ";
} else{
$where="WHERE rooms.roomType='" . $room_type . "' AND ";
$where2="OR (reservations.arrivalDate IS NULL AND rooms.roomType='" . $room_type . "')";
}
$sql = "SELECT rooms.roomID AS roomID,
rooms.roomType AS roomType,
count(rooms.roomID) AS bookCount
FROM reservations
RIGHT OUTER JOIN rooms ON reservations.roomID = rooms.roomID " .
$where . "((reservations.roomStatus='Confirmed' OR reservations.roomStatus='Checked in')
AND
(
(reservations.arrivalDate > '" . $arrival_date . "' AND reservations.arrivalDate > '" . $departure_date . "')
OR
('" . $arrival_date . "' > reservations.departureDate AND '" . $departure_date . "' > reservations.departureDate)
)
)"
. $where2
. "GROUP BY roomType,roomID ORDER BY roomType,roomID";
$num_rows=mysql_num_rows(mysql_query($sql));
if ($num_rows == 0) {
$availability= "not available";
$sql = "SELECT rooms.roomID AS roomID,
rooms.roomType AS roomType,
count(rooms.roomID) AS bookCount
FROM reservations
RIGHT OUTER JOIN rooms ON reservations.roomID = rooms.roomID
WHERE (
(reservations.roomStatus='Confirmed' OR reservations.roomStatus='Checked in')
AND
(
(reservations.arrivalDate > '" . $arrival_date . "' AND reservations.arrivalDate > '" . $departure_date . "')
OR
('" . $arrival_date . "' > reservations.departureDate AND '" . $departure_date . "' > reservations.departureDate)
)
)
OR reservations.arrivalDate IS NULL
GROUP BY roomType,roomID ORDER BY roomType,roomID";
} else {
$availability="available";
}
$result=mysql_query($sql);
$num_rows=mysql_num_rows($result);
$sqlTotalBookings="SELECT roomID AS roomID,COUNT(roomID) AS totalBookings FROM reservations GROUP BY roomID";
$resultTotalBookings=mysql_query($sqlTotalBookings);
while ($bookTotal=mysql_fetch_array($resultTotalBookings)) {
$roomNum=$bookTotal['roomID'];
$bookings=$bookTotal['totalBookings'];
$total[$roomNum]=$bookings;
}
?>