Adding year options to a drop down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Yardawg
Forum Newbie
Posts: 2
Joined: Mon Jan 05, 2009 11:19 am

Adding year options to a drop down

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Adding year options to a drop down

Post by VladSun »

What do you set the $curYear to?
Take a look at getdate() PHP function.
There are 10 types of people in this world, those who understand binary and those who don't
Yardawg
Forum Newbie
Posts: 2
Joined: Mon Jan 05, 2009 11:19 am

Re: Adding year options to a drop down

Post by Yardawg »

I don't see a getDate, but this is the line I think it is using:

$curYear=date("Y");
Post Reply