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!
Could potential solutions to this:
Code Side
You could do something like this:
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).