I am still relatively new to php so bear with me. I have looked a number of times at other examples, but still cannot figure this out.
I have an add page where I have a drop down that is populated by a query. This works as needed. My issue is now on an edit form, getting the dropdown box to show the value from the database field.
<select name="lvmID" id="lvmID">
<option value="">--Select--</option>
<?php
include ('../datalogin.php');
$list=mysql_query("select luchtvaartmaatschappijID, luchtvaartmaatschappij from
tbl_luchtvaartmaatschappij WHERE inactive='0' Order by luchtvaartmaatschappij ASC");
while($row_list=mysql_fetch_assoc($list)){ ?>
<option value="<?echo $row_list['luchtvaartmaatschappijID']; ?>">
<?echo $row_list['luchtvaartmaatschappij']; ?>
</option>
<?
}
?>
</select>
This works as expected on the Add form. But when I get to the Edit form to change the information for that page. The Select dropdown still populates, but I can't figure out how to get it so that the value from the database table where the values are stored (not the values from the dropdown) does not become selected.
So maybe the value should be '1747' 'KLM Royal Dutch Airlines'. I can't figure out to get it so when I go to bijwerk.php this value does not already become selected in the dropdown.
bijwerk.php - pulls information from tbl_vluchtgegevens table.
<body>
<? include "datalogin.php";//database connection
$order = "select vg.*, lh.luchthavencode as vertrekluchthavencode, lh2.luchthavencode
AS aankomstluchthavencode, lvm.luchtvaartmaatschappij AS lvmnaam,
lvm.luchtvaartmaatschappijID, t.toestel AS toestelnaam, k.reisklass, r.reizen,
k.reisklass, vt.vluchttype AS revenue
from tbl_vluchtgegevens vg
left join tbl_luchthaven lh
on vg.vertrekluchthaven = lh.luchthavenID
left join tbl_reizen r
on vg.reisID = r.reizenID
left join tbl_luchthaven lh2
on vg.aankomstluchthaven = lh2.luchthavenID
left join tbl_toestel t
on vg.toestel = t.toestelID
left join tbl_klass k
on vg.reisklasse = k.klassID
left join tbl_vluchttype vt
on vg.vluchttype = vt.vluchttypeID
left join tbl_luchtvaartmaatschappij lvm
on vg.luchtvaartmaatschappij = lvm.luchtvaartmaatschappijID
WHERE gegevenID='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<table border=1>
<tr>
<td width="646" align=center>bijwerk vluchtgegevens: <br>
ID = <? echo "$row[gegevenID]"?></td>
<td width="505" align=center> </td>
</tr>
<td><select name="lvmID" id="lvmID">
<option value="">--Select--</option>
<?php
include ('../datalogin.php');
$list=mysql_query("select luchtvaartmaatschappijID, luchtvaartmaatschappij from
tbl_luchtvaartmaatschappij WHERE inactive='0' Order by luchtvaartmaatschappij ASC");
while($row_list=mysql_fetch_array($list)){ ?>
<option value="<?echo $row_list['luchtvaartmaatschappijID']; ?>" <?php echo
($row_list['luchtvaartmaatschappijID'] == $_POST['lvmID']) ?
'selected="selected"' : '' ?>>
<?echo $row_list['luchtvaartmaatschappij']; ?>
</option>
<?
}
?>
</select></td>
</table>
<?php
// close connection
mysql_close();
?>
</body>
</html>