Cauton Posted November 14, 2011 Share Posted November 14, 2011 Hello everyone, and thanks in advance for trying to help me. I'm an IT student in Rotterdam, and I've got a little problem here. It's probably basic to most of you guys, but I've only been working with php for the past 3 months or so. I'm making a website for some company, and they want a reservation system. I've created everything so far, except for the fact that you can actually double book. Can you guys tell me how to make sure you can't book a reservation when that time is used by another reservation? Preferably even, when making the reservation, the reserved times aren't even chooseable. In my database I have the current info: table: reservations id (PK, UQ, A_I) date (date) starting time (time example: 09:00:00) ending time (time example: 10:00:00) ~Some other random information needed by that company~ Now it doesn't need to come to minutes or seconds, you can only reserve for whole hours, from and untill the hour. I made the script that puts everything in the database and everything, I just need a little script on how to check if the time on the date you selected earlier (it's like a step system, step 1 select date, step 2 select time, step 3 fill in other random info) is already reserved, and to make sure the reserved times don't appear into the dropdown menu for the times. I hope you guys can help me. Quote Link to comment https://forums.phpfreaks.com/topic/251113-reservation-issue/ Share on other sites More sharing options...
KevinM1 Posted November 14, 2011 Share Posted November 14, 2011 You need to try a SELECT query on the date/time/whatever it is that would indicate a conflict before attempting to INSERT a new reservation. Something like (pseudo-code, adjust to fit your needs): $query = "SELECT id FROM reservations WHERE day = $day AND start_time >= $start_time AND end_time <= $end_time"; When you run the query, count the number of rows it returns. If it's >= 1, you have reservation(s) booked already: $result = mysql_query($query); if (mysql_num_rows($result) >= 1) { // error: something has already been reserved } else { // insert new reservation } Quote Link to comment https://forums.phpfreaks.com/topic/251113-reservation-issue/#findComment-1288000 Share on other sites More sharing options...
Cauton Posted November 14, 2011 Author Share Posted November 14, 2011 Great thanks a lot, looking at the script I feel like an idiot for not figuring that out haha! The website is now finished, awesome! Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/251113-reservation-issue/#findComment-1288013 Share on other sites More sharing options...
KevinM1 Posted November 14, 2011 Share Posted November 14, 2011 Quote Link to comment https://forums.phpfreaks.com/topic/251113-reservation-issue/#findComment-1288015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.