Jump to content

Archived

This topic is now archived and is closed to further replies.

j007ha

generate year drop down list

Recommended Posts

how am i going to generate a auto year drop down list by using php?

 

For example : now the year is 2008, so i want the drop down list to generate a drop down list which consists the year before 3 and after 3 years of the year 2008.

 

So what i want is

 

<option>2005</option>

<option>2006</option>

<option>2007</option>

<option>2008</option>

<option>2009</option>

<option>2010</option>

<option>2011</option>

 

i very very appreciate any help from u all ^^ ;D

Share this post


Link to post
Share on other sites
<select>
<?PHP
$year = date("Y") - 4; for ($i = 0; $i <= 6; $i++) {$year++; echo "<option>$year</option>";}
?>
</select>

Share this post


Link to post
Share on other sites

Slightly less stupid way... sorry, it's 3am... XD

 

<select>
<?PHP
$year = date("Y") - 3; for ($i = 0; $i <= 6; $i++) {echo "<option>$year</option>"; $year++;}
?>
</select>

 

P.S. - I would edit, but it doesn't let me anymore.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.