DOB drop down issue

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
benjaminj88
Forum Newbie
Posts: 21
Joined: Fri May 02, 2008 2:31 pm

DOB drop down issue

Post by benjaminj88 »

Alright well I am currently trying to make a registration page for my website, and I would rather not sit there coding each year going back 100 years. So I made my attempts at creating a drop down menu with php using the -- decrement from the current year and working with while statements but my code keeps generating just the drop down menu with the first entry i made before placing my decrement/loop. Can anyone help me out here?
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: DOB drop down issue

Post by lafever »

Let's see your code so it can be critiqued.
User avatar
Verminox
Forum Contributor
Posts: 101
Joined: Sun May 07, 2006 5:19 am

Re: DOB drop down issue

Post by Verminox »

It's as simple as:

Code: Select all

<select name="year" id="year">
<?php
    $current_year = (int)date("Y");
    for($i=$current_year; $i>=($current_year-100); $i--)
    {
        echo "<option value='$i'>$i</option>";
    }
?>
</select>
It's probably a small logic error in your code. Post the code if you were going for something else.
benjaminj88
Forum Newbie
Posts: 21
Joined: Fri May 02, 2008 2:31 pm

Re: DOB drop down issue

Post by benjaminj88 »

wow thanks a lot, found the problem finally after comparing the two, was pretty lame that I messed up on a simple error, but i doubt I would have caught it anyways thanks again, saved me a lot of time, and saved my page from being so long.
Post Reply