<?php
$from = 200606;
$to = date('Ym');
//define sort, print first title
$sort = date('Y');
echo "<h3>{$sort}</h3>";
//minus $to until $to = $from
while ($from != $to) {
//break down $to
$toYear = substr_replace($to, '', 4, 6);
$toMonth = substr_replace($to, '', 0, 4);
//if new year, add title
if ($sort != $toYear) {
$sort = $toYear;
echo "<h3>".$toYear."</h3>";
}
//make text month, print link
$month = date('F', mktime(0,0,0,$toMonth,0,$toYear));
# echo "<a href='/news/{$toYear}/month-{$month}.html'>{$month}</a> <br />";
echo $toYear.$toMonth." - ".$month."<br />";
//minus 1 month, if less than zero, new year
$toMonth = $toMonth-1;
if ($toMonth == 0) {
$toMonth = 12;
$toYear = $toYear-1;
}
//add 0 if only 1 digit
if (strlen($toMonth) == 1) {
$toMonth = '0'.$toMonth;
}
$to = $toYear.$toMonth;
}
?>
it almost works, I don't know what I did wrong. the line I commented out is printing the wrong month from mktime() (as demonstrated in the line below it), its always one month off.. does anyone know why?