Ordering <option> values in PHP
Posted: Sun Nov 06, 2011 12:20 pm
In my registration form, I have a huge list of years. The list auto populates itself from the function. Example:
When I populate it that way, it orders itself from 1900-2011 when i want it to order in a descending manor without ever using MySQL for it.
Any suggestions?
Code: Select all
<?php
function reg_date($name, $startyear, $endyear) {
// Populate year drop menu
$return = "<select id='year' name='".$name."year'>";
$return .= "<option>YEAR</option>";
for($i=$startyear;$i<=$endyear;$i++) {
$return .= "<option value='".$i."'>".$i."</option>";
}
$return .= "</select>";
return $return;
}
echo reg_date("name", 1900, 2011);
?>Any suggestions?