大家好,感謝您的時間。將所選國家/地區從數據庫導入選擇框
我使用下面的查詢從我的數據庫獲取信息:
$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