Numeric <select> Generator

Generates a with a given name and numeric options from the two values specified ($start and $end). It also can have a default item selected:

[php]/* display_select by http://jsherz.com */
function display_select($select_name, $start, $end, $selected = -1) {
ob_start();
echo ‘’;
for($i = $start; $i < ($end + 1); $i++) {
if($selected != -1 && $selected == $i) {
echo ‘’, $i, ‘’;
} else {
echo ‘’, $i, ‘’;
}
}
echo ‘’;
$result = ob_get_contents();
ob_end_clean();
return $result;
}[/php]

Example usage:

[php]echo display_select(‘test_select’, 1, 10, 4);[/php]

Produces:

[php]12345678910[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service