I need to do this a lot and I've found that creating a function to create the select menu works well. I often need to call it in more than one place.
Here's an example of a function that I would use. Note that the parameter being passed, $selected is set to 0, that is the default if no value is passed to the function. If you are looking to have a particular option selected, pass the id to the function.
function CategoryDDmenu($selected=0)
{
$Query = "SELECT id,name FROM table_name ORDER BY sort_key ASC";
$Result = mysql_query($Query);
if($Result){
if(mysql_num_rows($Result) <= 0){ print "NO RESULTS FOUND!"; }
else {
print "<select name=\"fieldname\">\n";
if($selected == 0){
print "<option value=\"0\" selected> -- SELECT AN OPTION -- </option>\n";
}
while($RowData = mysql_fetch_array($Result)){
print "<option value=\"" . $RowData['id'] . "\"";
if($selected == $RowData['id']){ print " selected"; }
print ">" . $RowData['name'] . "</option>\n";
}//END while
print "</select>\n";
}
} else {
print "DATABASE QUERY ERROR!";
}//END if
}//END function CategoryDDmenu
Hope this helps,