Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 循环日期函数_Php_Html_Mysql - Fatal编程技术网

Php 循环日期函数

Php 循环日期函数,php,html,mysql,Php,Html,Mysql,我在数据库中有表名“guest_room”,guest_room字段为“到达”和“离开”,到达值为“2016-12-27”,离开值为“2016-12-31” 在我的php文件中,我想显示从到达日期到离开日期的数据,下面是我的代码: $date = $g[arrival]; $end_date = $g[departure]; while (strtotime($date) <= strtotime($end_date)) {

我在数据库中有表名“guest_room”,guest_room字段为“到达”和“离开”,到达值为“2016-12-27”,离开值为“2016-12-31”

在我的php文件中,我想显示从到达日期到离开日期的数据,下面是我的代码:

$date = $g[arrival];
$end_date = $g[departure];
while (strtotime($date) <= strtotime($end_date)) {                                       
$date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
echo "$date<br>";
}
$date=$g[到达];
$end_date=$g[出发];
虽然(strotime($date)尝试此代码

$date =  "2016-12-27" ;
$end_date = "2016-12-31";
while (strtotime($date) <= strtotime($end_date)) {
    echo "$date<br>";
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}
$date=“2016-12-27”;
$end_date=“2016-12-31”;
虽然(strotime($date)尝试此代码

$date =  "2016-12-27" ;
$end_date = "2016-12-31";
while (strtotime($date) <= strtotime($end_date)) {
    echo "$date<br>";
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}
$date=“2016-12-27”;
$end_date=“2016-12-31”;
而(strotime($date)尝试以下方法:

$date = $g[arrival];
$end_date = $g[departure];
while (strtotime($date) < strtotime($end_date)) {                                       
$date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
echo "$date<br>";
}
$date=$g[到达];
$end_date=$g[出发];
而(strotime($date)”;
}
试试这个:

$date = $g[arrival];
$end_date = $g[departure];
while (strtotime($date) < strtotime($end_date)) {                                       
$date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
echo "$date<br>";
}
$date=$g[到达];
$end_date=$g[出发];
而(strotime($date)”;
}
/** *生成两个日期之间的字符串日期数组 * *@param string$开始日期 *@param string$结束日期 *@param string$格式输出格式(默认值:Y-m-d) * *@return数组 */

然后,您将按预期调用该函数:

getDatesFromRange('2010-10-01', '2010-10-05');
/** *生成两个日期之间的字符串日期数组 * *@param string$开始日期 *@param string$结束日期 *@param string$格式输出格式(默认值:Y-m-d) * *@return数组 */

然后,您将按预期调用该函数:

getDatesFromRange('2010-10-01', '2010-10-05');

只需先回显日期,然后增加日期

while (strtotime($date) <= strtotime($end_date)){
    echo "$date<br>";
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}

while(strotime($date)只需首先回显日期,然后增加日期

while (strtotime($date) <= strtotime($end_date)){
    echo "$date<br>";
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}

while(strotime($date)只需将增量放在循环体的末尾:

$date = $g[arrival];
$end_date = $g[departure];
while (strtotime($date) <= strtotime($end_date)) {                                       
    // Switched these lines so the increment is at the end of the body
    echo "$date<br>";
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}
$date=$g[到达];
$end_date=$g[出发];

而(strotime($date)只需将增量放在循环体的末尾:

$date = $g[arrival];
$end_date = $g[departure];
while (strtotime($date) <= strtotime($end_date)) {                                       
    // Switched these lines so the increment is at the end of the body
    echo "$date<br>";
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}
$date=$g[到达];
$end_date=$g[出发];
而(strtime($date)
$date=“2016-12-27”;
$end_date=“2016-12-31”;
而(strotime(“+1天”,strotime($date))
$date=“2016-12-27”;
$end_date=“2016-12-31”;

而(strotime(“+1天”,strotime($date))只是…切换循环中的两行?(即输出后递增)只是…切换循环中的两行?(即输出后递增)由于您在输出之前也会增加,因此这仍然会从
2016-12-28开始。您好,它工作正常,但仍然是错误的,您的代码显示从“2016-12-28”开始到“2016-12-30”您预期的日期是什么?输出1:27,28,29,30,31 op2:27,28,29,30?$date=“2016-12-27”$end_date=“2016-12-31”;因此将显示2016-12-27 2016-12-28 2016-12-29 2016-12-30 2016-12-31那么这应该是一个好答案。
$date=“2016-12-27”$end_date=“2016-12-31”;而(strotime($date)仍然将从
2016-12-28开始,因为您在输出之前也会增加…您好,它工作但仍然错误,代码的结果显示开始“2016-12-28”到“2016-12-30”您期望的日期是什么?输出1:27,28,29,30,31 op2:27,28,29,30?$date=“2016-12-27”$end_date=“2016-12-31”;因此将显示2016-12-27 2016-12-28 2016-12-29 2016-12-30 2016-12-31,那么这应该是一个很好的答案。
$date=“2016-12-27”$end_date=“2016-12-31”而(strottime($date)与OPs和@Naga的解决方案相同:仍将延迟1天开始(如上图所示,2016-12-28)与OPs和@Naga的解决方案相同:仍将延迟1天开始(如上图所示,2016-12-28)将正常工作,考虑到他只需将增量放在循环末尾并完成,可能有点过头。(你不会做
while($我会做得很好,考虑到他只需要把增量放在循环的末尾就可以了,这可能有点过头了。)(你不会做
while($我当然会做,为什么不会?编辑:当然会,为什么不会?编辑: