我需要制作月度访问报告,进一步细分为每个月的每周摘要。我有一个SQL结果数组,其中包含月份编号,周编号以及周开始日期和结束日期。
Month Week week start weekend
1 1 12/27/2015 1/2/2016
1 2 1/3/2016 1/9/2016
...
2 6 1/31/2016 2/6/2016
2 7 2/7/2016 2/13/2016
如果它们都是同一个月的一部分,我想遍历这个数组并为每周创建表。然后在月末,回显月度汇总表,然后移动下个月。以下是一些示例代码:
while ($weekarr=odbc_fetch_array($weekresult))
{
$week1 = date('m.d.Y', strtotime($weekarr['weekstart']));
$week2 = date('m.d.Y', strtotime($weekarr['weekend']));
if ($weekarr['month']==$i)
{
echo "<table border='1' style='float: left' width=1 cellpadding='5'>";
echo "<tr style='background-color:#484848;color:white'><td colspan='4'>Week of ".$week1." to ".$week2;
echo "<tr><td>Membership</td><td>Visitors</td><td>Purchased</td> <td>Comped</td></tr>";
}//end if
else
{ echo monthly table
$i++;
}
} //end while
1月结束后(月份= 1),每个新月的第一周都会被跳过。如何在不跳过每月第一周的情况下增加$ i?
答案 0 :(得分:3)
while ($weekarr=odbc_fetch_array($weekresult))
{
$week1 = date('m.d.Y', strtotime($weekarr['weekstart']));
$week2 = date('m.d.Y', strtotime($weekarr['weekend']));
if ($weekarr['month']==$i)
{
echo "<table border='1' style='float: left' width=1 cellpadding='5'>";
echo "<tr style='background-color:#484848;color:white'><td colspan='4'>Week of ".$week1." to ".$week2;
echo "<tr><td>Membership</td><td>Visitors</td><td>Purchased</td> <td>Comped</td></tr>";
}//end if
else
{ echo monthly table
echo "<table border='1' style='float: left' width=1 cellpadding='5'>";
echo "<tr style='background-color:#484848;color:white'><td colspan='4'>Week of ".$week1." to ".$week2;
echo "<tr><td>Membership</td><td>Visitors</td><td>Purchased</td> <td>Comped</td></tr>";
$i++;
}
} //end while
基本上,您希望在失败条件
中为该一周的成功条件运行输出