🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.basic.visual.misc
2 messages
2 total messages Started by Chad Gough Wed, 07 Apr 1999 00:00
Nested Loops
#425
Author: Chad Gough
Date: Wed, 07 Apr 1999 00:00
61 lines
2395 bytes
I have 2 loops in an ASP page.
sql1 with rsa (sql call 1 with record set a)
sql2 with rsb (sql call 2 with record set b)

<%
On Error Resume Next
rsa.MoveFirst
do while Not rsa.eof
art = Server.HTMLEncode(rsa.Fields("Artist").Value)
%>

                                <table with first record from sql1>
<%
On Error Resume Next
rsb.MoveFirst
do while Not rs.eof
%>
                                                <table with first record
from sql2 where value is from sql1>
                                                <table with second record
from sql2 where value is from sql1>
                                                <table with third record
from sql2 where value is from sql1>

<%
rsb.MoveNext
loop
%>
<%
rsa.MoveNext
loop
%>

The results I WANT are:

RecordA
        Value1
        Value2
        Value3
RecordB
        Value4
        Value5
        Value6
(values 1, 2, and 3 have a value of A in field2 and values 4, 5, and 6 have
a value of B in field2)

I'm GETTING:
RecordA
        Value1
        Value2
        Value3
RecordB
        Value1
        Value2
        Value3

The call to sql2 only seems to work in the first loop.  Do I have to reset
rsb or something?  If so how?


Thanks.
Re: Nested Loops
#427
Author: Stefano Valsecchi
Date: Fri, 09 Apr 1999 00:00
32 lines
1511 bytes
You need to re-execute the second query in each loop of the first one:

<%
On Error Resume Next
rsa.MoveFirst
do while Not rsa.eof
art = Server.HTMLEncode(rsa("Artist"))
%>
                                <table row with a record from sql1>
<%
rsb.Open ("SELECT * FROM table WHERE field2 = ' " & rsa("field1") " ' ",
connection, adOpenForwardOnly
rsb.MoveFirst
do while Not rsb.eof
%>
           <table row with a record from sql2 where value is from sql1>

<%
        rsb.MoveNext
    loop
    rsb.Close

    rsa.MoveNext
loop
%>



Bye

Stefano
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads