i need to populate a dropdown menu with date from database, this is what i've done so far
<div class="col-md-6">
<?php
$query_user_group = mysqli_prepare ($conn, "
SELECT group_name
, group_id
FROM user_group_join
LEFT
JOIN user_group
ON user_group_join . group_join_id = user_group . group_id
WHERE user_join_id = ?
");
mysqli_stmt_bind_param($query_user_group, 'i', $client_id);
mysqli_stmt_execute($query_user_group);
mysqli_stmt_bind_result($query_user_group, $group_name, $group_id);
mysqli_stmt_fetch ($query_user_group);
mysqli_stmt_close($query_user_group);
?>
<div class="form-group">
<label class="control-label">Condominio in gestione*</label>
<select class="bs-select form-control" name="usergroup">
<option value="<?php echo $group_id;?> " selected="selected"><?php echo $group_name;?></option>
<?php
$select_group_query= mysqli_prepare($conn, "SELECT group_id, group_name FROM user_group");
mysqli_stmt_execute($select_group_query);
mysqli_stmt_bind_result($select_group_query, $idgruppo, $nomegruppo);
while(mysqli_stmt_fetch($select_group_query))
{
echo "<option value= '".$idgruppo."'>" . $nomegruppo . "</option>";
}
?>
</select>
<span class="help-block"> Assicurati di aver creato una scheda condominio! <br>Per inserire un nuovo condominio <a href="admin_create_new_group.php">Clicca Qui</a></span>
</div>
</div>
The problem is that the dropdown shows the selected value twice in the dropdown, any idea how i can sort it out? This is a screenshot of the error enter image description here Many thanks