r/PHPhelp • • 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

7 comments sorted by

View all comments

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.

1

u/MonsieurKyro Oct 09 '17

Here https://pastebin.com/F84GKSdW, i'm currently trying to output values on the table which I can't seem to do. (Please don't mind the other clutter, I'm only concerned about trying to filter out the entries that are available in between dates that the user entered). Here's my other php as well https://pastebin.com/Giw0JnZs . Thanks.