Here is a function I use to return a pulldown box. Run your query and build an array from the results, then pass this as $items to the function.
For example:
$items = array( "dave"=>1, "kev"=>2, "sally"=>3 );
$form = get_dropdown( "fm_mate", $items, 2 );
$form contains the HTML code for the form, with "kev" selected. You would the use $POST['fm_mate'] to find the selected value. If the user chooses "dave", $POST['fm_mate'] will be 1.
/**
* Generates and returns a pulldown menu for a form.
*
* @access public
* @param string $name
* @param array $items Array of options. Title => value.
* @param string $selected Value of selected item in array $items.
* @return string
*/
function get_dropdown( $name, $items, $selected )
{
$content = "<select name=\"$name\" id=\"$name\">";
foreach ( $items as $title=>$value ) {
$content .= "<option value=\"$value\" ";
if ( $selected == $value ) {
$content .= 'selected="selected"';
}
$content .= ">$title</option>";
}
$content .= "</select>";
return $content;
}