dubc07 Posted July 29, 2008 Share Posted July 29, 2008 I'm trying to put together a code that will allow users to book slots in airplanes. I have everything figured out except for the over booking features. This is how i want to start on the verifications $month = 'September'; $day = '10'; //display all the news $result = mysql_query('SELECT * FROM `rentme` WHERE `month`="'.$month.'" AND `day`="'.$day.'"'); //run the while loop that grabs all the news scripts while($r=mysql_fetch_array($result)) { //grab the title and the ID of the news $time=$r["time"];//starttime $plane=$r["plane"]; $intrv=$r["intrv"]; $endtime=$r["endtime"];///endtime echo "$plane $time $intrv $endtime<br>"; } /////this will output below/// 2 800 120 1000 /// 2 is airplane 800 is start time in military 120 is the interval and 1000 is end time. Is there a way to have php check the start time and end time and not allow post between those times. The example would be there is a plane booked at 8am till 10am and some other person try's and books the airplane for 830am till 930am but php would check database and send error back? Any help is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
obsidian Posted July 29, 2008 Share Posted July 29, 2008 By far, the easiest way would be to store your start time and end times as DATETIME fields. Then, you never have to worry about querying separately on the date and times. As it is, though, you probably would want to do something like this (keep in mind that you have to see if you have overlap on the new start/end times as well as if any of the current reservations overlap within your current time): I'm going to write this assuming that all dates and times are stored as valid DATETIMES for simplicity. You can break it down further into your own format if you need to. <?php $plane = 2; $start = '2008-01-02 08:00:00'; $end = '2008-01-02 10:00:00'; $q = "SELECT COUNT(*) AS count FROM rentme WHERE plane = $plane AND (start_time BETWEEN '$start' AND '$end' OR end_time BETWEEN '$start' AND '$end' OR '$start' BETWEEN start_time AND end_time OR '$end' BETWEEN start_time AND end_time)"; $sql = mysql_query($q); $count = mysql_result($sql, 0, 'count'); if ($count > 0) { // There is a conflicting reservation } ?> Doing your dates and times in this fashion also allows for checking multi-day rentals, if you are supporting this. If I rent it at 10PM until 2AM, as your current system is set up, that would require two separate reservations, but if you use the DATETIME for your start and end time, you can use the same query I show above to take care of those as well. Hope this helps! Quote Link to comment Share on other sites More sharing options...
dubc07 Posted July 29, 2008 Author Share Posted July 29, 2008 The codes that you have provided are solid However my scripts work off of military time and i can't seem to do a conversion. i was just going to see if theres some math that can be done in order to verify. Thanks. Quote Link to comment Share on other sites More sharing options...
dubc07 Posted July 29, 2008 Author Share Posted July 29, 2008 anyone else have any idea's ? Quote Link to comment 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.