I want to insert a value from the database into my dropdown menu in php. Here's what I'm looking to do: I have an edit form page which pulls info from the database and populates itself. However, the dropdown menu is hardcoded and I want the value from the database to be the one that is selected when that pages loads, this allows the user to keep that value or pulldown the menu and select something else.
Is there any way of doing this? I don't know if I'm making any sense at all :)
<html>
<head>
</head>
<body>
<select>
<option>Select employ</option>
<?php
mysql_connect('localhost','user','pass');
mysql_select_db('employ');
$query="select id, name from employ order by name asc";
$result=mysql_query($query);
while(list($id, $name)=mysql_fetch_row($result)) {
echo "<option value=\"".$id."\">".$name."</option>";
}
?>
</select>
</body>
</html>
That code is for reading and dynamically creating a dropdown menu, but that is not what I'm looking for. Instead, the dropdown has already been created on the client side before the page loads - so I want just the 'name' that is returned from the database to be selected in the dropdown menu just like other values are displayed in the form.
Any help would be appreciated.