Previously asked question by a user
Below is the my SQL code.
$find=mysqli_query($dbconn,"
SELECT *
FROM room
WHERE room_no NOT IN
(SELECT room_no
FROM reservation
WHERE check_in<='$check_out'
AND check_out>='$check_in');
Imagine someone has booked room number 100 for 12.07 to 12.10. Another one search for the 12.10 to 12.12 for same room? Then it showing no rooms available. My checkin time for the room is 02.00 pm. Checkout is 10.00 am. So how could I fixed this.
(Eg. Someone has book room no 100 for 12.07 to 12.10. His checkout will be on 12.10 10.00 am. Then another can be booked room no 100 on 12.10 to 12.12. Because his checkin time will be 02.00 pm in 12.10.)
I guess I explained it.
Awaiting for your kind helps.
Thank you.
PS.
Room Table
----------
id room_no status
1 100 1
2 101 1
Reservation Table
-------------------
id room_no check_in check_out
1 100 2020.12.07 2020.12.10
I have also tried this sql code also. But same results.
$find=mysqli_query($dbconn,"SELECT * FROM room WHERE room_no NOT IN (SELECT room_no FROM reservation WHERE(check_out>='$check_in' AND check_in<='$check_out')OR(check_out<='$check_in' AND check_in>='$check_out'))");
If you want to allow check out and check in on the same day, you just have to allow the ranges to meet up; Change <=
to <
and change >=
to >
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.