[PHP] Dynamic Year Drop Down

2006-11-16 Thread Albert Padley
I want to build a select drop down that includes last year, the current year and 3 years into the future. Obviously, I could easily hard code this or use a combination of the date and mktime functions to populate the select. However, I'm looking for a more elegant way of doing this.

Re: [PHP] Dynamic Year Drop Down

2006-11-16 Thread Larry Garfield
Quite simple: $this_year = date('Y'); for ($i= $this_year-1; $i $this_year+3; ++$i) { print option value='$i' . ($i==$this_year ? selected='selected' : '') . $i/option\n; } Obviously modify for however you're doing output. (Note that you DO want to have the redundant value attribute in

Re: [PHP] Dynamic Year Drop Down

2006-11-16 Thread Albert Padley
On Nov 16, 2006, at 11:04 PM, Tom Ray [Lists] wrote: Albert Padley wrote: I want to build a select drop down that includes last year, the current year and 3 years into the future. Obviously, I could easily hard code this or use a combination of the date and mktime functions to populate

Re: [PHP] Dynamic Year Drop Down

2006-11-16 Thread Albert Padley
Thanks, Larry. This was close, but didn't quite work. I played around with the syntax and the following worked great. $this_year = date('Y'); echo select\n; for ($i= $this_year-1; $i $this_year+3; ++$i) { echo option value='$i'; if($i == $this_year) echo