I am doing a booking page for house renting.
I have a datepicker were my users submits a UNIX datetime: Arrival and Departure date.
On mySQL I have a house with different seasons with "season_start" date (YYYY-mm-dd), "season_end" date & "price per day".
$seasons_select="SELECT id,season_start,season_end,daily_price FROM ".T_ITEM_SEASONS." WHERE id_item=".ID_ITEM." ORDER BY season_start ";
$res_seasons=mysql_query($seasons_select) or die("Error getting states");
$arrival_date = date('d-m-Y', $arrival_date);
$departure_date = date('d-m-Y', $departure_date);
while ($seasons_row=mysql_fetch_assoc($res_seasons)){
$start_date = date('d-m-Y', strtotime($seasons_row["season_start"]));
$end_date = date('d-m-Y', strtotime($seasons_row["season_end"]));
$current_date = $start_date;
while($current_date != $end_date){
$current_date = date("d-m-Y", strtotime("+1 day", strtotime($current_date)));
$match_date = $arrival_date;
while($match_date != $departure_date){
$match_date = date("d-m-Y", strtotime("+1 day", strtotime($match_date)));
if ($current_date==$match_date){
echo $current_date.' This is one of the days! <br />';
}
}
}
}
What is the best way to match if a date inside the user arrival/departure period is inside one or severall seasons?
My code kind of works...
I get the answer I want but after it a "Fatal error: Maximum execution time of 30 seconds exceeded in"