User input room type, start time and end time to check the room availability. I have 2 tables in my database which is Room and Booking. How to select the room based on the type of room and the availability? Note that $sport is the room type because I try to create system for sport facility rental system.
Room
- type_sport
- Fee
- roomCode
Booking
- roomCode
- time_end
- time_start
- date
I think the error might be at the $result because when I run the code it display 'No result found.'(even though I don't click the submit button) which is should display when there is no room available.
$sport=$_POST['sport'];
$date = $_POST['date'];
$start =$_POST['time_start'];
$end = $_POST['time_end'];
$result = mysql_query("SELECT r.roomCode FROM Room r WHERE r.roomCode NOT IN
(SELECT b.roomCode FROM Booking b WHERE(b.time_end >= '$start' AND b.time_start <= '$end')
OR (b.time_end <= '$start' AND b.time_start >= '$end'))AND (r.type_sport = '%$sport%')");
if (!$result)
{die(mysql_error());}
if(mysql_num_rows($result) > 0)
{
while($row= mysql_fetch_array($result))
{
echo $row['type_sport'];
echo $row['roomCode'];
echo $row['fee'] ;
}
}
else {echo "No result found.";}
It should display the room that available on that date and time based on type of sport user choose but what my code display is 'No result found.'