r/PHPhelp • u/MonsieurKyro • Oct 09 '17
Checking for availability between dates
So basically I am to make a reservation system for a resort. I have already made a database: https://imgur.com/f9aLyFZ. I really need to know how to check if dates are available when making a reservation.
So far I did this: $sql = "SELECT * FROM room_type_tbl
INNER JOIN room_tbl ON room_type_tbl.room_type_id=room_tbl.room_type_id
WHERE room_type_tbl.room_capacity='$roomcap' && ('$datein'>booking_tbl.checkin_date && '$dateout'<booking_tbl.checkoutdate)
";
if ($conn->query($sql) === TRUE) {
//echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}It's not working and I'm about to go mad. Please help me.
8
Upvotes
1
u/wh33t Oct 09 '17
Is room_id and room_number ever going to change? If not, copy over room_number to booking_tbl and it would be so easy. It would be a single query, with no joins.
If you want to maintain the table join you are attempting to use, please post the output and any errors you are receiving. Better yet, post a sample SQL dump so I can rebuild the structure and work on the queries myself.