Jump to content
xisto Community
alex198555

Year Birth? Interesting PHP Issue

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.