Hi,
I am working on a property rental website. I have a form with 2 date fields, check in and check out, both posted to check.php to check for availability.
I have a table named 'Calendar' with 2 columns, propertyID, and date. If a property is booked, there is a row in my calendar table, like so:
propertyID | Date
1234 | 2010-03-21
If the property is available in the selected range, no rows are added in the table.
Here comes my problem...
If a property is booked, it displays:
8731 is Booked. Date: 2010-03-26
If a property is available, it displays:
8731 is Booked. Date: 2010-03-26
4564 is Available. Date: 2010-04-20
4564 is Available. Date: 2010-04-21
8731 is Available. Date: 2010-03-26
8731 is Available. Date: 2010-03-29
I need to exclude the rows that are booked from the rows that are available, I have been toying around with this for a while with no luck.
This is my code so far:
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
//FORMATS THE DATE
$checkinvar = explode('/',$checkin);
$start = $checkinvar[2].'-'.$checkinvar[0].'-'.$checkinvar[1];
$checkoutvar = explode('/',$checkout);
$end = $checkoutvar[2].'-'.$checkoutvar[0].'-'.$checkoutvar[1];
$query = "SELECT * FROM calendar";
$result = mysql_query($query) or die(mysql_error());
$query_a = "SELECT * FROM calendar WHERE date BETWEEN '$start' AND '$end'";
$result_a = mysql_query($query_a) or die(mysql_error());
$returned_rows = mysql_num_rows($result_a);
if($returned_rows != 0)
{
while ($row = mysql_fetch_array($result_a))
{
echo $row['propertyID'].' is Booked. Date: '.$row['date'].'<br />';
}
}
while ($var = mysql_fetch_array($result))
{
echo $var['propertyID'].' is Available. Date: '.$var['date'].'<br />';
}
Any help will be greatly appreciated.