First of all it's suicide to put queries inside looping structures and CF
has accounted for that by allowing you to group query output.

Try this instead:


(SQL and ACCESS)
----------------------------------------------
<cfquery name="menu" datasource="batu2">
        SELECT c.id AS catID, m.id AS menuID 
        FROM categories c
             LEFT OUTER JOIN
                menu m ON
                c.ID = m.parent
        ORDER BY c.id
</cfquery>

<cfoutput query="menu" group="catID">
        #catid#::<br>
        <cfoutput>#catid#:#menuid#<br></cfoutput>
</cfloop>

       
(ORACLE)
----------------------------------------------
<cfquery name="menu" datasource="batu2">
        SELECT c.id AS catID, m.id AS menuID 
        FROM categories c, menu m
        WHERE c.ID = m.parent(+)
        ORDER BY catID
</cfquery>

<cfoutput query="menu" group="catID">
        #catid#::<br>
        <cfoutput>#catid#:#menuid#<br></cfoutput>
</cfloop>

                                             
Bryan Love ACP
Internet Application Developer
Telecommunication Systems Inc.
[EMAIL PROTECTED]
                                                    


-----Original Message-----
From: xrussx [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 15, 2001 5: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/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to