2017-03-02 97 views
-1

請幫忙。以下代碼運行良好,但創建重複值。我該如何解決這個問題。我想我把分裂功能放在錯誤的地方。比較數據並創建複選框

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

您需要檢查您是否找到了結果。

嘗試:

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 
相關問題