This solution won't work. What is happening is that you are referring
to only the first row in your inner cfloop, in regards to querya, which
is why you are only getting the output of the first value in the first
row. Reversing the process will simply reverse the output you are
getting, not solving your problem.
You need to make sure you are referring to the right row for querya; the
row and column name are implicit in the inner cfloop, so you don't have
to preface them:
<cfloop query="querya">
<cfset thisrow = querya.CurrentRow>
<cfoutput query="queryb">
#querya.val[thisrow]#: #val_for_query_b#<br>
</cfoutput>
</cfloop>
(also, note the cfoutput for the inner query loop instead of using a
cfloop with a cfoutput inside)
I am referring to the value for querya using array notation. There are
other ways to get the same result. For instance, you could name the
field you want to output where you would set the "thisrow" variable, and
display the field name that way inside the cfoutput, instead of keeping
track of the current row that querya is on. Either way, it won't
matter. I didn't test the speed for the different methods, so it's best
to try a few and see which performs better, based on the amount of data
you need to output.
#val_for_queryb# would be the name of the field from queryb that you
want to output. You do not need to preface this with "queryb." since it
is implicit, like I explained in the first paragraph above, nor do you
need to keep track of which row the inner cfoutput loop is on, as that
is implicit as well. Basically the inner row count and variable names
take precedence over any outer loops with the same variable names.
-Andy
> -----Original Message-----
> From: John Paitel [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, October 03, 2001 5:36 PM
> To: CF-Talk
> Subject: Re: Nested Loops (query)
>
>
> Reverse your loops:
>
> <cfloop query="queryb">
> <cfloop query="querya">
> #querya.val#, #queryb.val#
> </cfloop>
> </cfloop>
>
> John
>
>
> At 04:24 PM 10/3/01 -0400, you wrote:
> >OK, I feel like I've done this before, but maybe not. Can anyone
> explain to
> >me how to do this and get my desired result.
> >
> ><cfloop query="querya">
> >
> > <cfloop query="queryb">
> >
> > #querya.val#: #queryb.val#
> >
> > </cfloop>
> >
> ></cfloop>
> >
> >What I want is, if querya had 2 rows and queryb had 3 rows, to
> get 6 rows of
> >output like this:
> >
> >querya.row1: queryb.row1
> >querya.row1: queryb.row2
> >querya.row1: queryb.row3
> >querya.row2: queryb.row1
> >querya.row2: queryb.row2
> >querya.row2: queryb.row3
> >
> >Instead I get:
> >
> >querya.row1: queryb.row1
> >querya.row1: queryb.row2
> >querya.row1: queryb.row3
> >querya.row1: queryb.row1
> >querya.row1: queryb.row2
> >querya.row1: queryb.row3
> >
> >Thanks in advance.
> >
> >- Sean
> >
> >
> >
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists