Dude,
First of all you have to read all records returned from the DB. You cannot fetch the whole result table from the database using a single php function. PHP can retrieve only one record at a time, so if you want to retrieve all rows from the SQL result, you have to type this many times mysql_fetch_array(), as many rows have been returned from the sql query.
Please check my post here, explaining result retrieval.
http://www.daniweb.com/forums/thread156511.html
Then, once you have all your data, you can proceed with selected / non-selected verification of values in the <select> element.
Instead of loading a variable with name $selected, in my opinion it is better that you do the following
if ($result[key] == $_POST[whatever]
{
echo '<option value="'.$result[key].'" selected="selected">Whatever text here</option>';
}
else{
echo '<option value="'.$result[key].'">Whatever text here</option>';
}