大家好,感谢您的时间。将所选国家/地区从数据库导入选择框
我使用下面的查询从我的数据库获取信息:
$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 ";
}
它工作正常,但我面临的问题是,如果3人是来自荷兰,选择框会显示3次荷兰。其他国家也是如此。
因此,例如:
user 1 is from The Netherlands
user 3 is from The Netherlands
user 6 is from The Netherlands
当选择框中点击它显示:
Belgium
Canada
Luxemburg
Netherlands
Netherlands
Netherlands
同样的事情也发生在其他国家。
任何想法如何解决这个问题?
提前致谢!
感谢您的帮助。你的第一个解决方案就像一个魅力。你能解释一下你的第二个解决方案是什么意思吗? – moonwalker 2011-04-26 01:17:55
第二个答案与@ mu的答案基本相同(他的答案更详细:)) – 2011-04-26 01:26:05