我认为你正在编辑系统中的用户。您希望能够通过允许登录的用户从选择框中进行选择来更改其用户类型。
我建议如下:
首先,需要将用户类型表读入数组。数组键需要是用户类型id,值需要是描述。
当您要显示用户类型id时,请改为显示该索引的新数组值。
显示此字段进行编辑时,请与原始问题中的代码完全相同,但如果选项与正在编辑的用户的用户类型匹配,则也将其表示为“选定”。
//$user will have all the data for the user you are editing
$query = "SELECT * FROM user_types";
$result = mysqli_query($connections, $query);
$user_types = array();
while($rows = mysqli_fetch_assoc($result)){
$db_id = $rows["user_type_id"];
$db_desc = $rows["description"];
$user_types[$db_id] = $db_desc;
}
?>
Select Type
foreach($user_types as $id => $desc){
if ($user['user_type_id'] == $id){
echo "$desc";
}else{
echo "$desc";
}
}
?>
当您处理正在提交的表单时,$_POST['user_type']中的值将是所选用户类型对应的用户类型id。