Page 1 of 1

How to increase year list to one on completion of year

Posted: Tue May 29, 2007 12:39 pm
by amir
Hello,
I have to display years from 1940 to 2006 in a drop down and when 2007 would be completed, it should come in that drop down too. How can I do this?

For taking 1940 to 2006 in the drop down, i am doing this

Code: Select all

<select id="yy" name="yy">
     <?
	for($i = 1940; $i <= 2006; $i++) {				  	  echo "<option>{$i}</option>";
	}
     ?>								       </select>
Now, when the date 2007 'll end, it should be in that drop down too.
TIA.

Posted: Tue May 29, 2007 12:46 pm
by nyfael
Sorry - not quite getting your question. Are you just trying to get it to go up to 2007 as the last item?

Code: Select all

<select id="yy" name="yy">
<?
        for($i = 1940; $i <= 2007; $i++) {                                
               echo "<option>{$i}</option>";
        }
?>               
</select>
That will end on 2007

Posted: Tue May 29, 2007 12:48 pm
by Oren

Posted: Tue May 29, 2007 1:04 pm
by amir
thanks for your quick response what I want to have is if some year gets completed, it should be show in my drop down. for example, 2006 is done and it is in my list and when 2007 'll be done then it should come into my list too similarly with 2008, 2009 and so on...

Posted: Tue May 29, 2007 1:09 pm
by Oren

Code: Select all

$year = date('Y') - 1;
for($i = 1940; $i <= $year; $i++) {

Posted: Tue May 29, 2007 1:19 pm
by amir
Oren; it works great
thanks a lot ;)