Link to home
Start Free TrialLog in
Avatar of RickyGtz
RickyGtz

asked on

Loop through records to show values on drop down menu

I am trying to check wheter there is a Recorset flight1 , fligtname2, flghtname3 ,  till flightname6  and display that in my selection menu, How would I do That??
<select name="flightSelect<%=p%>" id="flightSelect<%=p%>">
<option value selected="0">Select One</option>
                        <%
While (NOT Recordset2.EOF)
%>
<option value="<%=(Recordset2.Fields.Item("Flight1").Value)%>"><%=(Recordset2.Fields.Item("Flight1").Value)%></option>
   <option value="<%=(Recordset2.Fields.Item("Flight2").Value)%>"><%=(Recordset2.Fields.Item("Flight2").Value)%></option>
                        <%
  Recordset2.MoveNext()
Wend
If (Recordset2.CursorType > 0) Then
  Recordset2.MoveFirst
Else
  Recordset2.Requery
End If
%>
                      </select>

Open in new window

Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

I am not sure that I follow what it is that you are trying to do??
Could you please better explain it?
Avatar of RickyGtz
RickyGtz

ASKER

sure, I have a table in database which has fields

Fligh1
Flight2
.
.
Flight6  (last)


so I want to have a drop down list that shows the falues of each flight, now it can be the case that theres is only 2 flights , or 1 flight

so I wan to have a condition in my code to loop trhough the table and display when there is a value on a flight,, sorry for my english,
Going to throw this out, let me know if this is what you are wanting?
Do you want a dropdown list for "Each" of the "Fields" within' your table?

Dropdown_Flight1
Dropdown_Flight2
.....
Dropdown_Flight6

And each Dropdown will display the values for the given field.

If that is what you are wanting that is pretty simple to do.
BUT
If you are wanting something else, then please be a little more specific.
(Your English is great, your explaination,,,,, not so much, but getting there)

I will asume that it is the "Each" "Field" Per DropDown.
And I will put something together for you, unless you tell me other wise.

Carrzkiss
Yes.  Thats what i want. but the problem is as I mentioned before, that sometimes fields  Flight4, Flight5 are going to be empty so I want to prevent an error while trying to display an empty set .
this kinda works, but, I am sure to make this shorter and stronger..
 <select name="flightSelect<%=p%>" id="flightSelect<%=p%>">
<option value selected="0">Select One</option>
                        <%
While (NOT Recordset2.EOF)
if Recordset2.Fields.Item("Flight1") <> "" then 
 
%>
<option value="<%=(Recordset2.Fields.Item("Flight1").Value)%>"><%=(Recordset2.Fields.Item("Flight1").Value)%></option>
<% end if%>
 
<% if Recordset2.Fields.Item("Flight1") <> "" then %>
<option value="<%=(Recordset2.Fields.Item("Flight2").Value)%>"><%=(Recordset2.Fields.Item("Flight2").Value)%></option>
<% end if%>
 
<% if Recordset2.Fields.Item("Flight3") <> "" then %>
<option value="<%=(Recordset2.Fields.Item("Flight3").Value)%>"><%=(Recordset2.Fields.Item("Flight3").Value)%></option>
<% end if%>
 
 
<% if Recordset2.Fields.Item("Flight4") <> "" then %>
<option value="<%=(Recordset2.Fields.Item("Flight4").Value)%>"><%=(Recordset2.Fields.Item("Flight4").Value)%></option>
<% end if%>
 
 
 
<% if Recordset2.Fields.Item("Flight5") <> "" then %>
<option value="<%=(Recordset2.Fields.Item("Flight5").Value)%>"><%=(Recordset2.Fields.Item("Flight5").Value)%></option>
<% end if%>
 
 
 
<% if Recordset2.Fields.Item("Flight6") <> "" then %>
<option value="<%=(Recordset2.Fields.Item("Flight6").Value)%>"><%=(Recordset2.Fields.Item("Flight6").Value)%></option>
<% end if%>
 
 
 
 
   
                        <%
  Recordset2.MoveNext()
Wend
If (Recordset2.CursorType > 0) Then
  Recordset2.MoveFirst
Else
  Recordset2.Requery
End If
%>
                      </select>

Open in new window

OK.
I thought that you said "Yes" to
Each Flight would have it's own Menu?

In your example.
You have 1 menu, with all flights
I am confused as to what you are wanting?
Yes, is what I have on my code one menu with all flights, Actually that code works, but I think is not the best way to do it, Meabe a loop,? I also have a Table Field called NFlights which can delimit the loop

say for i=1 to Nflights>?
Let me know if this is what you are wanting?
The 1st Flight {Has no Records}
The rest of the Flight(s) Has 3 Records each.

http://www.pcitdad.com/Test/EE/Q_24124252/Group.asp
Oh I am sorry, yes , I did not get your question right. No I want only one Drop Down with all o f them like ion the last code posted.
ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes , only show available flights . I know is hard to visualize this. Give a sec here is the live page :

http://www.playerscores.net/admin/members/ad_setpairings.asp?TourID=37

Your code seems to work fine for what you are wanting to do.

What exactly is the problem?
You list has all available flights showing.
It does not give any errors when a Field has NO Records.

I really do not understand what it is that you are wanting to change here?
Except, maybe to try and make the code a little better, maybe?

You mentioned a Loop, that I can check in on, if that is what you are wanting.

( I am sorry about the long winded, but just trying to understand what it is that you are wanting to accomplish, so that I may best help you in your issue(s))
Yes I think it works now, I was thinking to short the code a little bit , but yes it work find , I am closing this question I thank you for your help so Far, I have anopther issue on this page and that is in fact , in a loop I have on the page to display the Groups, as you notice I have A Team Number and several players, but only the first one get the value I sleect on the group and I prefer to insert on all of them each member.
Thanks please look related issue.
do you have the post up?
If so, then send over the link.

Accept your Comment as answer (With the code you supplied that works)
http://Q_24124252.html?cid=238#a23587608
(I think that I did that right?)
I was referring to you accepting your own Post as Answer

[02.09.2009 at 12:40AM EST, ID: 23587608]
Where you supplied the working code.

Or did you just want to give me points?
Well yes, but thats fine, dont think I can change it now.
You could, by posted it to the https://www.experts-exchange.com/Community_Support/General/
And telling the that you awarded it to me, and meant to award your "Coded Post"

It is ok with me if you change it, as I did not do anything to assist in this issue really.
Except to point out the obvious and that was on the other post....
ok, Is fine as it is. I think it does not worth chaning it now. Lets just move to nect post. Thanks