I am trying to make a form combobox
that brings me the values of a department of the bd
, to later modify them, in combobox
it all the departments are shown, and I have a form in which I edit the department of the equipment, the problem is that I do not know how leave selected the combobox
one with the department that is in the database.
The first of the departments is not selected and taken. This is the code I use to display the combos. I want it to leave the one in the database selected, to later modify it.
$link = mysql_connect("localhost", "root","");
mysql_select_db("lfmt",$link);
$consulta=mysql_query("select * from depto")or die('Fallo Query: ' . mysql_error());
<?php
echo '<select name= "Deptos">';
do {
echo '<option value=" ' .$row["idDepto"].' ">'.$row["Nombre"].'</option>';
}
while ($row = mysql_fetch_array($consulta));
echo "</select>";
?>
What you have to do is use that variable
resedit[2]
to check which of the departments you need to be selected and useselected
theoption
.With a comparison we will know which is the ID that you have already recovered and only to that we indicate the property
selected
.Thanks Kenny Barrera I was looking for a solution like this for several weeks for a similar case I had with some
select
in a data update form.