我有两张桌子:
geoCountry
带列的表 1
country_name | country_code
user_countries
带列的表 2
country_name | username
我想设置用户国家预选(即从数据库中获取)
这是我尝试过的代码
<select multiple="multiple" class="country" style="width: 200px">
<%
sql6 = "SELECT DISTINCT countryname FROM user_countries WHERE username = ?";
ps6 = connection.prepareStatement(sql6);
ps6.setString(1, user);
rs6 = ps6.executeQuery();
while (rs6.next()) {
usercountries.add(rs6.getString(1));
}
for (int i = 0; i < geoCountry.size(); i++) {
for (int j = 0; j < usercountries.size(); j++) {
if (usercountries.get(j).equals(geoCountry.get(i))) {
%>
<option value="<%=geoCountry.get(i)%>" selected="selected"><%=geoCountry.get(i)%></option>
<% } else {%>
<option value="<%=geoCountry.get(i)%>"><%=geoCountry.get(i)%></option>
<% }
}
} %>
</select>
它在选择框中显示重复的值..为什么?