Heres a good site on Dynamic Option lists
http://www.quirksmode.org/js/options.html
Heres some code on PHP Generated option boxes
// Build a select list from an array
function build_select($selArr, $selOpt) {
$selectText = $selOpt[0];
$select = "";
if ($selectText != "") {
$selDefault = "selected=\"selected\"";
if ($selOpt[1] == "true") {
$selDefault = "";
}
$select .= "<option value=\"$selectText\" $selDefault>$selectText</option>\n";
}
foreach($selArr as $key => $value) {
$sel = "";
for ($loop = 2; $loop < count($selOpt); $loop++) {\
// Done to circumvent the key type being set to numerical when it needs to stay as a string!!!
if (gettype($key) == "integer") {
$keystring = "0" . $key;
if ($selOpt[$loop] == $keystring) {
$sel = "selected=\"selected\"";
}
} else {
if ($selOpt[$loop] == $key) {
$sel = "selected=\"selected\"";
}
}
}
if (eregi("OPTGRPSTART", $key)) {
$select .= "<optgroup label=\"$value\">\n";
} elseif (eregi("OPTGRPEND", $key)) {
$select .= "</optgroup>\n";
} else {
$select .= "<option $sel value=\"$key\">$value</option>\n";
}
}
return $select;
}
Thats the function I use, found it somewhere and modified it alot
Modified to let you use option groups, also I ran into a problem with PHP setting the array key to a numeric data type, so the comment above is the section to hack...err fix it
here is the code to call the function
<select name="orderby">
<?php echo build_select($orderby, array("", "true", $_SESSION['orderby_field'])); ?>
</select>
The first variable is the array you will be using to get the values from, the first set of quotes is the default value, the should be boolean, true or false, thats used to save the last selected option, and the last variable is where the last selection was saved too