I've seen similar problems in my stuff. 

My solution was as follows:
if I needed to refer to a query element from the outer loop, I would assign
it to a variable.  Then whereever I needed it in the second loop, I would
refer to the variable.

A bit of a kludgy fix, but it worked, and I don't forsee any significant
performance hit as the recordsets I'm dealing with have relatively small
rowcounts on an underutilized server.

my two cents.

Shawn Grover

-----Original Message-----
From: xrussx [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 15, 2001 6:03 PM
To: CF-Talk
Subject: nested loops/queries


I'm having a weird problem doing a nested loop and a nested query.  I
have two queries.  The topmenu query returns ids 1,2,3 and 4.  The
leftmenu query  returns ids 5,6,7,8,9 for topmenu.id=1 and 14,15,16 for
topmenu.id=3.  The queries are right and return the right data.  For
some reason when I'm trying to output it, it messes up the topmenu.id
and thinks that it's 1 when it's supposed to be 3.  Below is the code
and the output.  Am I doing something wrong?


<cfquery name="topmenu" datasource="batu2">
        select id 
        from categories
        order by orderid
</cfquery>

<cfloop query="topmenu">
        <cfoutput>#topmenu.id#::<br></cfoutput>
        <cfquery name="leftmenu" datasource="batu2">
                select id
                from menu
                where parent=#topmenu.id#
        </cfquery>
        <cfloop query="leftmenu">
                <cfoutput>#topmenu.id#:#leftmenu.id#<br></cfoutput>
        </cfloop>
</cfloop>




1::
1:5
1:6
1:7
1:8
1:9
2::
3::
1:14
1:15
1:16
4::

Russ
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to