Hi guys, Im trying to put together a booking system with a prevention script to ensure you can't double book a cottage.
I have been putting it together mainly in 3 parts, the first part uses the SELECT MAX() script with two conditions, getting the largest departure date held in the booking table WHERE the begin date of the stored record returned is less than the arrival date selcted and passed on as a variable.
This is then repeated to return details for the next booking , these two details are then passed to an IF statement to see whether you can book it or not.
This is my scriptfor the first part mentioned (where im stuck)
<?php
$result = @mysql_query('SELECT MAX(end) as recentdate FROM booking WHERE cottage = '.$cottageid.' AND begin < '.$arrival.' ');
while ($row = mysql_fetch_array($result)) {
echo '<br><Br><br>'. $row['recentdate'].'' ;
}
?>
The thing is that this first piece of script (i set it to show the value returned to make sure it worked) returns nothing as it sits at the minute. However when you change the " AND begin > ......" It pulls the value in. The problem seems to be when the less than is used (the one I need) I have sample data in place for either side of the date variables passed on i.e. I have dates in the DB for booking 27-29 and for the 01-02 of the following month so theoretically if I use the dates 30-31 in the query I should get the details for the booking from 27-29.... BUT I DONT!!!
(note: the cottage Id's match up no problem)
Any ideas guys, I posted this up on another forum but didn't get a solution
Thanks in advance
Tim