Jump to content

Recommended Posts

i found this script to build a selection list based on the current year...this script always selects the current year and then adds one to the current year for an option. what i want to do is modify this to build a selection list for a set of years that displays this year and then 90 years before...so like 2009 through 1919. but im not familiar with how to use counters.

 

/* build selection list for the year */
$today = time();
$startYr = date("Y", $today);  //get the year from $today
echo "<select name='syear'>\n";
for ($syear=$startYr;$syear<=$startYr+1;$syear++)
{
   echo " <option value=$syear";
   if ($startYr == $syear )
   {
     echo " selected";
   }
   echo "> $syear\n";
}
echo "</select>\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/149206-solved-using-counters/
Share on other sites

/* build selection list for the year */
$today = time();
$startYr = date("Y", $today);  //get the year from $today
echo "<select name='syear'>\n";

$endYr = $startYr-90; // get the date you want to end up at
for ($syear=$startYr;$syear<=$endYr;$syear--)
{
echo " <option value=$syear";
if ($startYr == $syear )
{
	echo " selected";
}
echo "> $syear\n";
}
echo "</select>\n";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.