Hi, the inner loop should always print out " 1". Because in the inner loop
you loop through the second query not the first one and it simply excute the
statement : <cfoutput>#query_a.field_a#<cfoutput> as many time as the second
query's recordcount.
I have an example here:
<cfset Customer =
Querynew("SenderName,RecipientName,Subject,SenderEmail,RecipientEmail,Messag
e")>
<cfset TempCust = QueryAddRow(Customer)>
<cfset TempCust = QuerySetCell(Customer, "SenderName", "John")>
<cfset TempCust = QuerySetCell(Customer, "RecipientName"," Mary")>
<cfset TempCust = QuerySetCell(Customer, "Subject", "Dinner")>
<cfset TempCust = QuerySetCell(Customer, "SenderEmail", "[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(Customer, "RecipientEmail",
"[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(Customer, "Message", "arange a dinner
together")>
<cfset TempCust = QueryAddRow(Customer)>
<cfset TempCust = QuerySetCell(Customer, "SenderName", "Smith")>
<cfset TempCust = QuerySetCell(Customer, "RecipientName"," Black")>
<cfset TempCust = QuerySetCell(Customer, "Subject", "Dinner")>
<cfset TempCust = QuerySetCell(Customer, "SenderEmail", "[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(Customer, "RecipientEmail",
"[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(Customer, "Message", "arange a dinner
together")>
<cfset
cftalk=QueryNew("SenderName,RecipientName,Subject,SenderEmail,RecipientEmail
,Message")>
<cfset TempCust = QueryAddRow(cftalk)>
<cfset TempCust = QuerySetCell(cftalk, "SenderName", "John")>
<cfset TempCust = QuerySetCell(cftalk, "RecipientName"," Mary")>
<cfset TempCust = QuerySetCell(cftalk, "Subject", "Dinner")>
<cfset TempCust = QuerySetCell(cftalk, "SenderEmail", "[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(cftalk, "RecipientEmail",
"[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(cftalk, "Message", "arange a dinner
together")>
<cfset TempCust = QueryAddRow(cftalk)>
<cfset TempCust = QuerySetCell(cftalk, "SenderName", "Smith")>
<cfset TempCust = QuerySetCell(cftalk, "RecipientName"," Black")>
<cfset TempCust = QuerySetCell(cftalk, "Subject", "Dinner")>
<cfset TempCust = QuerySetCell(cftalk, "SenderEmail", "[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(cftalk, "RecipientEmail",
"[EMAIL PROTECTED]")>
<cfset TempCust = QuerySetCell(cftalk, "Message", "arange a dinner
together")>
This is the Cftalk example:<br>
<cfloop query="Customer">
<cfoutput>Firt loop:#Customer.SenderName#</cfoutput><br>
<cfloop query="cftalk">
<cfoutput>Second loop:#Customer.SenderName#</cfoutput><br>
</cfloop>
</cfloop>
/*The out put:
Firt loop:John
Second loop:John
Second loop:John
Firt loop:Smith
Second loop:John
Second loop:John*/
Sima
----- Original Message -----
From: Stephen Moretti <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 13, 2000 7:42 AM
Subject: RE: Multiple <CFLOOP>s
> >
> > I have 2 queries which require to loop through for certain execution.
> > However I discovered something
> >
> > <cfloop query="query_a">
> > <cfoutput>#query_a.field_a#<cfoutput>
> > <cfloop query="query_b">
> > <cfoutput>#query_a.field_a#<cfoutput>
> > </cfloop>
> > </cfloop>
> >
> > I realised that both #query_a.field_a# are different values, for the
first
> > one, it is able to list out all the different values. However for
> > the second
> > one, it only output the first value throughout.
> >
> > Is it something to do with multiple <cfloop>s ?
> >
> > Can somebody enlighten me on this ?
> >
>
> Eh....
>
> OK - if you get this result set from your query a and query b :
>
> QueryA QueryB
> FieldA Yourfield
> 1 a
> 2 b
> 3 c
>
> What you're going to get output is this:
> * 1
> 1
> 1
> 1
> * 2
> 2
> 2
> 2
> * 3
> 3
> 3
> 3
>
> The rows marked with a * are displayed in the outer loop and the other are
> displayed in the inner loop.
>
> The reason for this is that your inner loop is only going to loop round
the
> contents of QueryB and output the _current row_ from QueryA. On the first
> iteration of the loop on QueryA the displayed result is "1", then the
inner
> loop iterates through QueryB, but doesn't move onto the next record in
> QueryA. This means that for every iteration of QueryB on the first time
> round the QueryA loop you'll only get the result "1".
>
> Are you sure that you have specified your code snippet correctly and is
> there something else that you are doing in the loop that is missing from
the
> above snippet???
>
> Regards
>
> Stephen
>
> --------------------------------------------------------------------------
----
> Archives: http://www.mail-archive.com/[email protected]/
> To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.