Re: Dynamic Year Drop Down

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 there, otherwise some Javascript things 
don't work right in IE.  Good habit to get into.)  I don't think it can 
really get more simple and elegant.

On Thursday 16 November 2006 23:26, 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 the select. However, I'm looking for a more elegant way
> of doing this.
>
> Thanks for pointing me in the right direction.
>
> Al Padley

-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux