How to increase year list to one on completion of year

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
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

How to increase year list to one on completion of year

Post 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.
nyfael
Forum Commoner
Posts: 32
Joined: Thu Sep 21, 2006 2:28 am

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post 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...
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Code: Select all

$year = date('Y') - 1;
for($i = 1940; $i <= $year; $i++) {
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Oren; it works great
thanks a lot ;)
Post Reply