I have a table called person
with column called language.
And also I have another table called language_table
CREATE TABLE language_table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
designation VARCHAR(30) NOT NULL
)
It contains:
1 - english
2 - frensh
3 - arabic
4 - other
I wanted to put these 4 records into a <select
options.
I have created this code, it works perfectly fine, but I don't know how to add another <select>
with values from database.
How do I fetch the selected value from DB into <option>
?
<?php
$query = mysqli_query($con, "SELECT * FROM person WHERE id=$id");
while ($result = mysqli_fetch_object($query, $con)) {
?>
<select name="sexe">
<?php
if ($result->sexe == 'Masculin') {
echo"<option value='Masculin' Selected>Masculin</option>";
echo"<option value='Féminin' >Féminin</option>";
} else {
echo"<option value='Masculin' >Masculin</option>";
echo"<option value='Féminin' Selected>Féminin</option>";
} ?>
</select>
<?php
}
?>