So i have 3 tables, 2 with data and 1 to connect the other 2 through foreign keys.
It’s something like this:
student(ID_stud, etc)
specialization(ID_spec,spec_name)
study(ID_stud,ID_spec, etc)
Now i’m working at an Edit.php menu(i did the add menu with the list) and i need specializations in a drop-down-menu with the value from the mysql already selected
Here is what i did so far but i only get the correct value selected repeating itself n times
<select name="specialization" type="text">
<?php
$specialization=$_POST['specialization'];
$list_spec=mysql_query("SELECT * FROM specialization, study, student WHERE $ID_stud=study.ID_stud and specialization.ID_spec=study.ID_spec ");
$array_spec=mysql_fetch_array($list_spec);
while ($array_spec = mysql_fetch_array($list_spec)){?>
<option selected="<? echo $array_spec['ID_spec'] ?>"><?php echo $array_spec['spec_name'];?></option>
<?php }?>
</select>
You just need to set the
selectedattribute on the item that is selected. All the others will not have aselectedattribute. The value of this attribute does not matter.Something like this: