Jump to content

php verification


dubc07

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.