Adding year options to a drop down
Posted: Mon Jan 05, 2009 11:26 am
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.
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.