Page 1 of 1

Adding year options to a drop down

Posted: Mon Jan 05, 2009 11:26 am
by Yardawg
I'm very new to php and I'm simply trying to modify some existing code to display the years 2008 and 2009 instead of 2009 and 2010. I want to use varibales so I don't have to update it every year.

The code is currently
<?php
for($x=$curYear;$x<=$curYear+1;$x++) {
echo "<option value=\"".$x."\"";
if($curYear==$x) { echo "selected"; }
echo ">".$x."</option>\n";
}
?>

This shows this year + 1 as my options. I thought I could just change "$curYear+1" to "$curYear-1" and it would show 2009 and 2008, but I keep getting errors. Is this as simple as I'd expect. What should I do? Any help would be appreciated.

Re: Adding year options to a drop down

Posted: Mon Jan 05, 2009 11:30 am
by VladSun
What do you set the $curYear to?
Take a look at getdate() PHP function.

Re: Adding year options to a drop down

Posted: Mon Jan 05, 2009 12:50 pm
by Yardawg
I don't see a getDate, but this is the line I think it is using:

$curYear=date("Y");