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 3308402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:31:03+00:00 2026-05-17T21:31:03+00:00

I have some trouble with this. I have one database with the following tables:

  • 0

I have some trouble with this.

I have one database with the following tables:
Countries -> All countries of the world are added
Cities -> The cities are also added
user_profile -> The profile of the user with the fields “country” & “city”.

Everything works fine, even the populating of the boxes is working. But I don’t know how to get the SELECTED value of the user for both country & city.

I have the following code:

Select Country: <br />
<select id="countries">
<option value="">--</option>

<?php
$sql = "SELECT country, title FROM countries ORDER BY title ASC";

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"".$row['country']."\">".$row['title']."\n  ";
}
?>
</select>


Select City: <br />
<select id="cities">
<option value="">Select one</option>

<?php
$sql = "SELECT country, title FROM cities ".
"ORDER BY title ASC";

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
  echo "<option class=\"".$row['country']."\"  value=\"".$row['title']."\">".$row['title']."\n  ";
}
?>
</select>

Now I need to check in the table user_profile which country & city he chose and show it to him.

I also use jchained (jquery plugin) to make both select boxes working together.

How can I achieve this? If I need to post anything else, please let me know.

Thanks in advance.

  • 1 1 Answer
  • 1 View
  • 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-05-17T21:31:03+00:00Added an answer on May 17, 2026 at 9:31 pm

    You have a lot of missing code here but I will try to help.

    I am going to start by assuming that you have already stored the users selections in the user_profile table and that they are foreign keys to to correct relations.

    To get the selected id’s for repopulating the select boxes with the selected flag use:

    SELECT country, city FROM user_profile where id = $user_id;
    

    To get the text values you would do something like:

    SELECT country.title as country, city.title FROM user_profile LEFT JOIN countries ON user_profile.country = country.id LEFT JOIN cities ON user_profile.city = cities.id WHERE user_profile.id = $user_id;
    

    If you are not storing them as foreign key relations but instead by string title in the user_profile table you will need to do this:

    SELECT country.title as country, city.title FROM user_profile LEFT JOIN countries ON user_profile.country = country.title LEFT JOIN cities ON user_profile.city = cities.title WHERE user_profile.id = $user_id;
    

    You can then use these results to either display to the user or set the “SELECTED” flag in the options box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble figuring this out. I have an unordered list menu that
Im having some trouble writing a getstring function, this is what I have so
I have some trouble trying to join a couple of tables for a time-booking
I have some troubles with positioning my label/password field. With this code they both
I have some trouble with my trac installation (version 11.4). What should I do
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
I'm have some trouble with the fulltext CONTAINS operator. Here's a quick script to
I am mlearning javascript and have some trouble creating an onject via prototype. I
Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want

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.