在DB中,也有第26天和第31天但没有更改为OK。 仅获得第3天并更改为OK。PHP MYSQL日期范围错过日期
我在哪里错了这段代码?
代码:
*$from = date("Y-m-01");
$to = date("Y-m-t"); // last day current month
$query = "SELECT date FROM tbl_data WHERE date BETWEEN '$from' AND '$to' order by date DESC";
$result = mysqli_query($mysqli,$query);
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC))
{
$date = date_create_from_format('Y-m-d', $row['date']);
}
$cursor = date_create_from_format('Y-m-d', $from);
$finish = date_create_from_format('Y-m-d', $to);
while ($cursor != $date)
{
echo date_format($cursor,'Y-m-d') . "--- Missed <br>";
date_modify($cursor, '+1 day');
while($cursor == $date)
{
echo date_format($date,'Y-m-d') . "--- OK <br>";
date_modify($cursor, '+1 day');
}
while($cursor > $finish)
{
die();
}
}*
输出:
2016年7月1日---错过
2016年7月2日---错过
2016年7月3日---确定
2016年7月4日---错过
2016年7月5日---错过
2016年7月6日---错过
2016年7月7日---错过
2016-07-08 ---错过
2016-07-09 ---错过
2016-07-10 ---错过
2016-07-11 ---错过
2016-07-12 ---错过
2016年7月13日---错过
2016年7月14日---错过
2016年7月15日---错过
2016年7月16日---错过
2016-07-17 ---错过
2016-07-18 ---错过
2016-07-19 ---错过
2016-07-20 ---错过
2016-07-21 ---错过
2016-07-22 ---错过
2016-07-23 ---错过
2016-07-24 ---错过
2016-07-25 ---错过
2016年7月26日---错过
2016年7月27日---错过
2016年7月28日---错过
2016年7月29日---错过
2016-07-30 ---错过
2016-07-31 ---错过
我不明白你想问什么,请详细说明你的问题。 – Janno
不要关闭你的第一个while循环那里,关闭它在最后 – Rijin
没有改变我试过 –