imad imike;10990428 wrote:
a row for every week of the year. […] numbering each row 1 - 52.
That should be 1-53, since some years contain 53 weeks.
echo 'Do note that 2012-01-01 is in week ' . date('W', strtotime('2012-01-01')) . ' of "weekyear" ' . date('o');
$start_date = '2011-04-06';
# I believe it'd be easier to keep this as a timestamp due to your +7 days below
$check_date = strtotime($start_date);
$end_date = '2012-04-05';
echo '<table>
<thead>
<tr><th>Date</th><th>Week</th></tr>
</thead>
<tbody>';
# Instead of dieing at the end, if something goes wrong, I recommend keeping the
# check that $i < 53 here.
# Moreover, since you want numbering from 1-53, rather than 0-52, why not
# increment i in the while loop check, and see if it's less than 54
$i = 0;
# I turned $check_date into a timestamp, so now it needs to be turned into a
# date here
while (date('Y-m-d', $check_date) <= $end_date && ++$i < 54)
{
# Now easier to update check_date
$check_date = strtotime('+7 day', $check_date);
# If you want to output the value of $i, you have to be in PHP parsing mode.
# That means either jumping in and out of it for static vs dynamic content
# or output static content through PHP as well. I usually prefer the latter,
# at least unless I have bigger blocks of static content
printf('
<tr>
<td>%s</td>
<td>%d</td>
</tr',
date('Y-m-d', $check_date),
date('W', $check_date)
);
}
echo '
</tbody>
</table>';