首先,我不是一个程序员(只是一些PHP知识)。我做了一个网站的事件列表与选择字段过滤每月的事件与Ajax加载。
这段代码完美地运行了大约3个月。但在5天前,它停止了工作,开始生成无限循环。
我调试了代码,发现"while“循环就是问题所在。我在试着理解为什么这个方法在一段时间内工作得很好,然后它就不会了。(用无限循环使服务器崩溃)。
这个函数只给出下个月的第一天。它运行良好。
function first_day_next_month($month, $year){
$month = str_replace("0", "", $month);
if ($month == 12){
return ($year+1)."0101";
}else{
return $year.str_pad($month+1, 2, "0", STR_PAD_LEFT )."01";
}
}
这个选项为选择字段生成“选项”:
function ddown(){
$start = strtotime("10 December 2017");
$end = strtotime("+3 months");
$current = $start;
$meses = array(
"Jan" => "enero",
"Feb" => "febrero",
"Mar" => "marzo",
"Apr" => "abril",
"May" => "mayo",
"Jun" => "junio",
"Jul" => "julio",
"Aug" => "agosto",
"Sep" => "septiembre",
"Oct" => "octubre",
"Nov" => "noviembre",
"Dec" => "diciembre"
);
$o = "";
$selected = "";
$cls = " class=\"gray-out\"";
while ($current < $end){
if(date("m", $current) == date("m", strtotime("today")) AND date("Y", $current) == date("Y", strtotime("today"))){
$selected = " selected=\"selected\"";
$cls = "";
}else{
$selected = "";
}
$current = strtotime(first_day_next_month( date("m", $current), date("Y", $current) ));
}
return $o;
}
我发现这段代码现在正在生成无限循环:
while ($current < $end){
if(date("m", $current) == date("m", strtotime("today")) AND date("Y", $current) == date("Y", strtotime("today"))){
$selected = " selected=\"selected\"";
$cls = "";
}else{
$selected = "";
}
$current = strtotime(first_day_next_month( date("m", $current), date("Y", $current) ));
}
$current变量没有在while上更新。据我所知,这应该需要2017年12月10日到today+3月,以及这些日期之间每个月的输出和“选项”。
对如何解决这个问题有什么建议吗?
(对不起,我的英语)。
谢谢!
发布于 2018-07-09 05:55:36
在你的first_day_next_month函数中,你有:
$month = str_replace("0", "", $month);
这将用1替换10,这将在每年10月份恢复到1月份。
https://stackoverflow.com/questions/51236129
复制相似问题