我正在做一个房屋租赁的预订页面。
我有一个日期选择器,我的用户提交了一个 UNIX 日期时间:到达和离开日期。
在 mySQL 上,我有一个带有“season_start”日期(YYYY-mm-dd)、“season_end”日期和“每天价格”的不同季节的房子。
$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 />';
}
}
}
}
如果用户到达/离开期间内的日期在一个或多个季节内,最佳匹配方法是什么?
我的代码有点工作......
我得到了我想要的答案,但在它之后出现“致命错误:超过 30 秒的最大执行时间”