A Digital Age Deserves A Digital Leader

for loop help

for loop help

Postby xion`silo » Thu Jun 12, 2008 7:17 pm

I dont understand forloops and this is my attempt. lol
does any one know how to do a loop so that it adds a option for every year that is greater than the current year but no more than 5 years ahead?

Code: Select all
for($yearnum = date("Y", time()); $yearnum < $yearnum+2; $yearnum++)
{
   echo "  <option>$yearnum</option>";
}


i just really dont understand this
PRO New Member
Posts: 9
Joined: Mon Jun 02, 2008 5:27 am
Location: Austin, TX

Postby NoReflex » Thu Jun 12, 2008 9:58 pm

If I understand correctly what you need, you could try something like :
Code: Select all
$year = date("Y", time())
for ($i=1;i<6;i++)
{
   echo "<option>".$year+i."</option>";
}


If you want to include the current year you could try to run the loop from 0 to 5.
Hope this helps you!

Best wishes,
John
PRO Level 10
User avatar
Posts: 431
Joined: Wed Nov 17, 2004 8:41 pm
Location: Romania

Postby xion`silo » Mon Jun 16, 2008 5:11 am

thanks dude :)
PRO New Member
Posts: 9
Joined: Mon Jun 02, 2008 5:27 am
Location: Austin, TX

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 7 guests

cron
cron