Forum Moderators: coopster
$user_ctry = $_POST['country'];
(or loaded from a database, as in editing their info)
$select = "select c_code,c_fullname from $countries_table order by c_code asc";
// ASC is default anyway, but . . .
$select_list = '
<select name="country" id="country">
<option value="">Select</option>
';
// It is good practice, reliable at least, to have the top
// item blank in select lists, makes it easier to check input
$result=@mysql_query("$select");
while ($row=mysql_fetch_array($result)) {
$select_list .= '<option value="' . $row[0] . '"';
if ($row[0]==$user_ctry) { $select_list .= ' selected'; }
$select_list .= '>' . $row[1] . '</option>'; // use " if you want \n here
}
mysql_free_result($result);
$select_list .= '</select>';
echo $select_list;
// or return, if in a function, where it should be