I have a drop down menu that the user can select a location from. These are saved settings, so if the user wants to edit these settings I’d like for the previously saved value to populate the list.
The location and it’s ID are selected from a table named locations, however, only the location is saved in a table named userinfo. I’m not sure how to go about populating the selection list again considering the id is used in the selection process the first time around.
This is what i have right now to simply select a loation. I’d like for this to fill in with a previously saved location. This is part of a larger form, hence no form tags.
<?
$sql = mysql_query("select locationsid,locationsName from locations");
$selection="";
while ($row=mysql_fetch_array($sql)){
$id=$row["locationsid"];
$locationName = $row["locationsName"];
$selection.="<OPTION VALUE=\"$id\">".$locationName;
}
?>
<!--select location - used for reach location -->
<h4>Nearest Location</h4>
<table>
<tr><td>Location:</td><td><select name ="location"><Option value="<? echo selection2; ?>">Choose Location<? echo $selection; ?></Select></td>
</table>
I’m assuming I’d have to query the database to get the saved location (in userinfo table), then look up the ID for that location from the the locations table. From here, I’m not quite sure how to fill this into the value selection field.
$locationLookup = mysql_query("select location from userinfo where userid = $userid");
$locationLookup = mysql_fetch_array($locationLookup);
$location = $locationLookup['location'];
$idlookup = mysql_query("select locationsID from locations where locationsName = '$location'");
$idlookup = mysql_fetch_array($locationid);
$idlookup = $locationid['locationsID'];
So, this would give me the name and ID, how can I set this as the value in the selection list?
After you get
$idlookup:use it inside
whileloop: