Jump to content

[SOLVED] using counters


dadamssg

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.