alex198555 0 Report post Posted November 20, 2009 Many times, I noticed that when a user is registering, the web-site doesn't have many years of birth. It does have the necessary ones to choose from. How can I do it using the PHP? Share this post Link to post Share on other sites
truefusion 3 Report post Posted November 20, 2009 It'd be easier to just give them a text field where they can just type out their birth year. But i would expect the PHP code to generate dozens of birth years to be similar to this: <?phpecho "<select>";for ($year = startingYear(); $year < currentYear(); $year++) echo "<option value=\"$year\">$year</option>";echo "</select>";?>If you want a certain age limit, then have currentYear() subtract the age you want from the current year. Share this post Link to post Share on other sites
rubikcode 0 Report post Posted December 8, 2009 reviewing truefusion's code: <select name="year" id="year"> <?php for($i=date("Y"); $i<=date("Y")+2; $i++) if($year == $i) echo "<option value='$i' selected>$i</option>"; else echo "<option value='$i'>$i</option>"; ?></select> Share this post Link to post Share on other sites