Here is a function that I created and have in my php toolbox. I have function for creating alot of these tags and I feel it's faster and easier to create a form that is driven by DB content.
$selectName : Is the name you would like to the <SELECT> tag
$sqlString : Is the SQL string that you would like to pull the data from.
$tagExtras : Is a space to add tag properties such as class=""
$optionValue : Is the db field name of the field you would like to use for the item value.
$optionName : Is the db field name of the field you would like to use for the item display.
$selectedValue : Is the value you want to select.
$topOption/$bottomOption : Is <option> tags that are inserted at the beginning/end of the select tag.
function db2select($selectName, $sqlString, $tagExtras, $optionValue, $optionName, $selectedValue, $topOption = "", $bottomOption = "") {
$dbresult = mysql_query($sqlString);
if(!$dbresult||mysql_errno() > 0) {
$theSelectTag = "";
} else {
$theSelectTag = "<select name='{$selectName}' {$tagExtras}>";
if($topOption!=""){
$theSelectTag .= $topOption;
}
while ($row = mysql_fetch_array($dbresult)) {
if($selectedValue == $row[$optionValue]) {
$rowSELECTED = "SELECTED";
}else{
$rowSELECTED = "";
}
$theSelectTag .= "<option value='{$row[$optionValue]}' {$rowSELECTED}>{$row[$optionName]}</option>\n";
}
if($bottomOption != ""){
$theSelectTag .= $bottomOption;
}
$theSelectTag .= "</select>";
}
return $theSelectTag;
}