dadamssg Posted March 13, 2009 Share Posted March 13, 2009 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/149206-solved-using-counters/ Share on other sites More sharing options...
dadamssg Posted March 13, 2009 Author Share Posted March 13, 2009 i think i have to change the + signs to - signs, and then maybe change that < to a >, but i can't seem to get it right Quote Link to comment https://forums.phpfreaks.com/topic/149206-solved-using-counters/#findComment-783530 Share on other sites More sharing options...
Philip Posted March 13, 2009 Share Posted March 13, 2009 /* 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"; Quote Link to comment https://forums.phpfreaks.com/topic/149206-solved-using-counters/#findComment-783533 Share on other sites More sharing options...
dadamssg Posted March 13, 2009 Author Share Posted March 13, 2009 awesome thanks...you did forget to switch the < sign to a >. but doing that and it works perfect. thanks a mil Quote Link to comment https://forums.phpfreaks.com/topic/149206-solved-using-counters/#findComment-783535 Share on other sites More sharing options...
Philip Posted March 13, 2009 Share Posted March 13, 2009 Oops, sorry I should be in bed sleeping instead of surfin' the web Quote Link to comment https://forums.phpfreaks.com/topic/149206-solved-using-counters/#findComment-783539 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.