Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:04:06+00:00 2026-06-04T17:04:06+00:00

I have a drop down menu that the user can select a location from.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:04:08+00:00Added an answer on June 4, 2026 at 5:04 pm

    After you get $idlookup:

    $idlookup = $locationid['locationsID'];
    

    use it inside while loop:

    while ($row=mysql_fetch_array($sql)){ 
       $id=$row["locationsid"]; 
       $locationName = $row["locationsName"]; 
       $selected = ($id == $idlookup) ? 'selected="selected"' : '';
       $selection.="<OPTION " . $selected . " VALUE=\"$id\">".$locationName."</OPTION>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a drop down menu where a user can select from
I have setup a form that allows a user to make selections from drop-down
I have a drop down menu that looks great when the page it scrolled
So, I have an animated drop down menu that slides down when your mouse
I have built a drop-down menu here http://dev.driz.co.uk/jsonmenu/ that uses JSON to dynamically build
I have a table that includes a column for the user to select from
I have a select drop-down that selects a theme for the current page the
I have a form that allows a user to select a county from a
I have a drop down menu in an ASPX page along the lines of:
I have a drop down menu made with Jquery. Right now, if you hover

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.