Did you want Mon, Tue, Wed, Thur, Fri, Sat, Sun? Or 1, 2 , 3 ... 7.
Anyways, heres the code:
PHP Code:
<?php
$days = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$years = range(date("Y")-100, date("Y"));
function createSelect($array, $select_name){
$return = array();
$return[] = '<select name="'.$select_name.'">' . "\n ";
foreach($array as $drop){
$return[] = '<option value="'.$drop.'">'.$drop.'</option>' . " \n ";
}
$return[] = '</select>' . "\n ";
return implode("", $return);
}
echo createSelect($days, "days");
echo createSelect($years, "year");
?>
The arrays in the beginnings are just examples, its the function createSelect() you need.
Or, I made this code a while ago. It makes select menus except gives more options then the one above:
PHP Code:
<?php
$selects = array('Dogs', 'Cats', 'Tigers', 'Hippopotamus');
function select($array, $name, $limit = 5, $etc = true, $shorten_val = false){ //select( array_name , select_name, [limit], [display: ... after cutted])
$select = "<select name='{$name}'>\n";
foreach($array as $value){
$display_val = strlen($value) > $limit ? substr($value, 0, $limit).($etc ? "..." : "") : $value;
if($shorten_val){ $value = $display_val; }
$select .= "<option name='{$value}'>{$display_val}</option>\n";
}
$select .= "</select>\n";
return $select;
}
echo select($selects, 'type', 5, true, true);
?>
Bookmarks