Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help! remove duplicates when populating dropdown box

Status
Not open for further replies.

tuam1234

Technical User
Feb 6, 2004
52
IE
i am populating a dropdown box using the database and iv done this successfully. only problem is that i want to remove dublicates in the dropdown box.

any suggestions on how to achieve this are greatly appreciated!!

here's the code for populating dropdown box.



<%
Dim connection
Dim check
Dim loginData
Dim insert
Dim query

Set connection = Server.CreateObject("ADODB.Connection")
connection.Mode = 3
connection.Open("auction1")

Set loginData = Server.CreateObject("ADODB.RecordSet")

check= "SELECT Leaving, Destination, arrTime, depTime FROM Holidays"
Call loginData.Open(check,connection)
On Error Resume Next
%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional //EN">
<HTML>

<HEAD>
<TITLE> Choosen Prices</TITLE>
<link rel="stylesheet" href="../xml%20fligts/style.css" type="text/css">

<br>

<form method="post" name="formname" action="adminOptions.asp" onSubmit="return checksubmit()">
<TABLE>
</TABLE>
</FORM>

<tr><td>
Leaving From:
<TD><select name="Leaving">
<option value="noSelection">Select Your Departure Location
<%
If Request.Cookies ("Leaving")<>"" Then
Call Returning()
Else
Call NewUser()
End If
%>
<%
Sub Returning()
Dim found

found = False
While Not loginData.EOF
%> <OPTION
<%
If(Not found) Then

If Request.Cookies("Leaving")_
= loginData("Leaving")_
Then
Call Response.Write("SELECTED")
found = True
End If
End If
%>
Value = "<%=loginData("Leaving") %>">
<%=loginData ("Leaving")%>
<% Call loginData.MoveNext()
Wend
End Sub

Sub NewUser()
While Not loginData.EOF
%> <OPTION VALUE = "<%=loginData("Leaving")%>">
<%=loginData ("Leaving")%>
<% Call loginData.MoveNext()
Wend
Call loginData.MoveFirst()

End Sub
%>
 
check= "SELECT DISTINCT Leaving, Destination, arrTime, depTime FROM Holidays"

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
change your sql

"SELECT Distinct (Destination) , Leaving, arrTime, depTime FROM Holidays"
 
when i add in "Distinct" to the select as ye suggested, it groups all the same occurences together.

ie. before i added it in i got:
london
edinbouragh
london
london
edinbouragh

when distinct is added i get:
london
london
london
edinbouragh
edinbouragh

any suggestions??


 
You're trying to do a lot with one query/recordset and it might be making your task more difficult...
Code:
Sub NewUser()
    [b]lastCity = ""[/b]
    While Not loginData.EOF
       [b]if loginData("leaving") <> lastCity then[/b]
    %>    
        <OPTION VALUE = "<%=loginData("Leaving")%>">
        <%=loginData ("Leaving")%>
    <%
      [b]end if
      lastCity = loginData("leaving")[/b]
      Call loginData.MoveNext()
    Wend
    Call loginData.MoveFirst()

End Sub

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 

thanks for replying.

that doesnt seem to hav made any difference. im still getn duplicates..

 
This one is for new users and the "Leaving" cities must be grouped together (Like the last result set you posted).

You would also need to alter the "returning" subroutine...


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top