Problems with while loop date
Posted: Mon Aug 18, 2008 10:01 am
Hello,
I'm trying to write a while loop that will test first whether a file exists for previous months, and if so display a link to it, but for some reason I get an extra link...It seems to be going through the loop an extra time. Can someone tell me what I'm doing wrong?
Thanks!
I'm trying to write a while loop that will test first whether a file exists for previous months, and if so display a link to it, but for some reason I get an extra link...It seems to be going through the loop an extra time. Can someone tell me what I'm doing wrong?
Code: Select all
$i = -1;
$date = date("F", strtotime("$i month"));
$file = $date.".php";
while (file_exists($file) == true){
$date = date("F", strtotime("$i month"));
$file = $date.".php";
echo "<h2><a href=\"".$date.".php\">$date</a></h2>";
$i = $i-1;
}