php - Auto populate HTML Select box with years past and future -
whats best way auto populate select box in form years in php.
i want able 15 years in past current year , 5 years in future current year.
i have looked around online , can find populate x amount of years
<?php $currentvalue = 2008; $past = 15; $future = 5; if ($currentvalue && ($currentvalue < date('y') - $past || $currentvalue > date('y') + $future)) { echo "<option value=\"$currentvalue\" selected=\"selected\">$currentvalue</option>\n"; } ($year = date('y') - $past; $year <= date('y') + $future; $year++) { if ($year == $currentvalue) { echo "<option value=\"$year\" selected=\"selected\">$year</option>\n"; } else { echo "<option value=\"$year\">$year</option>\n"; } }
Comments
Post a Comment