请帮忙。以下代码运行良好但创建重复值。我该如何解决这个问题。我想我把拆分功能放在了错误的地方。
customer_choice=request.QueryString("customer_choice")
strSQL="Select distinct computer_name from item"
rs.Open strSQL, adoCon,1,1
rs.MoveFirst
while not rs.EOF
abc=split(customer_choice,",")
for i=0 to UBound(abc)
if rs("computer_name")=abc(i) then
response.Write("<input type='checkbox' id='c1' name='c1' value='" & rs("computer_name") & "' checked>" & rs("computer_name") & "</br></input>")
else
response.Write("<input type='checkbox' id='c1' name='c1' value='" & rs("computer_name") & "'>" & rs("computer_name") & "</br></input>")
end if
next
rs.MoveNext
wend
rs.Close
答案 0 :(得分:0)
您需要检查是否已找到结果。
尝试:
customer_choice=request.QueryString("customer_choice")
Dim userChoiceFound
strSQL="Select distinct computer_name from item"
rs.Open strSQL, adoCon,1,1
rs.MoveFirst
while not rs.EOF
abc=split(customer_choice,",")
userChoiceFound = false
for i=0 to UBound(abc)
if rs("computer_name")=abc(i) then
userChoiceFound = true
response.Write("<input type='checkbox' id='c1' name='c1' value='" & rs("district") & "' checked>" & rs("computer_name") & "</input>")
exit for
end if
next
if not userChoiceFound then
response.Write("<input type='checkbox' id='c1' name='c1' value='" & rs("computer_name") & "'>" & rs("computer_name") & "</br></input>")
end if
rs.MoveNext
wend
rs.Close