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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:12:18+00:00 2026-05-21T14:12:18+00:00

Hi all and thanks for your time. I’m using the following query to get

  • 0

Hi all and thanks for your time.

I’m using the following query to get information from my database:

$sql = "SELECT amember_countries.country, amember_countries.title, gold_profile.username, gold_profile.country AS userCountry 
        FROM amember_countries 
        LEFT JOIN gold_profile
        ON amember_countries.country = gold_profile.country

        ORDER BY amember_countries.title ASC
        ";

$rs = mysql_query($sql);

$selected = "";

while($row = mysql_fetch_array($rs))
{
    if ($row['userCountry'] == $row['country'] && $row['username'] == $username){
    $selected = "selected"; 
    }else{
    $selected = "";

    }
    echo "<option ".$selected." value=\"".$row['country']."\">".$row['title']."\n "; 
}

It works fine, but the problem I’m facing is if 3 people are from the Netherlands, the select box will show 3 times Netherlands. Same thing for the rest of the countries.

So for example:

user 1 is from The Netherlands
user 3 is from The Netherlands
user 6 is from The Netherlands

When clicking on the select box it shows:

Belgium
Canada
Luxemburg
Netherlands
Netherlands
Netherlands

The same thing is happening to the other countries.

Any idea how to solve this?

Thanks in advance!

  • 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-05-21T14:12:19+00:00Added an answer on May 21, 2026 at 2:12 pm

    Could potential solutions to this:

    Code Side

    You could do something like this:

    $a = array();
    while($row = mysql_fetch_array($rs))
    {
        if ($row['userCountry'] == $row['country'] && $row['username'] == $username){
        $selected = "selected"; 
        }else{
        $selected = "";
    
        }
        if(!in_array($row['country'], $a))
        {
           echo "<option ".$selected." value=\"".$row['country']."\">".$row['title']."\n "; 
           array_push($a, $row['country']);
        }
    }
    

    Database

    You could also tailor your database query to simply select the countries:

    SELECT * FROM FROM amember_countries GROUP BY amember_countries.country

    …Or something to that effect.

    I would personally suggest the database solution as that would be the “correct” solution (databases are made to solve this kind of problem).

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

Sidebar

Related Questions

Thanks for your time and assistance in advance. I am using TPL from WPF
first of all thanks for taking your time! I'm a junior Dev, working with
first of all, thanks for your time. I'm trying to use jqGrid to make
Hello all and thanks for your time. I believe I have a simple question.
Hello all and thanks for your time reading this. I need to verify certificates
Hi all and thanks for your time in advance. I have a problem trying
Thanks for all your help - see blow original question, and my edit following
first of all, thanks for your time. Like the subject says... i'm doing a
thanks for your time first...after all the searching on google, github and here, and
All, I have the following dynamic SQL Query DECLARE @TableName NVARCHAR(255); SET @TableName =

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.