At the risk of having seventeen other people tell you how to do it...

All that this code...

<cfoutput query="myQuery">
</cfoutput>

....does is:

<cfoutput>
<cfloop query="myQuery">
</cfloop>
</cfoutput>

Try using <cfloop> instead.

Also if you want to create a query based on another query, you have to loop
over the first query, create the new query, and then output that query:

<cfquery name="Query1" datasource="#dsn#">
SELECT * FROM myTable ORDER BY myField asc
</cfquery>

<cfoutput>
<cfloop query="Query1">
    <cfquery name="Query2" datasource="#dsn#">
    SELECT * FROM table WHERE aField = '#query1.myfield#'
    </cfquery>
    <cfloop query="Query2">
        #Query2.aField#<br>
    </cfloop>
</cfloop>
</cfoutput>

However, this is not efficient as there are going to be the same number of
database calls as there are records returned in the first query!  Try to use
the database to return a much more useful result set (if you're using MS SQL
Server that means a stored procedure - ask if you're not sure).  If you can
then output the resultset once, you only need to go to the database once and
you only need to output it once (and it's a lot easier on ColdFusion too!).

I hope this makes sense!

Paul
----------------------------
Paul Johnston
PJ Net Solutions Ltd
E: [EMAIL PROTECTED]
M: 07866 573013
----- Original Message -----
From: "Jones, Becky" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, March 13, 2001 1:57 PM
Subject: nesting queries


> I have 3 queries.  But when i try to nest the cfoutput tags i get an error
> that says this in to allowed.
> how do you use the cfoutput tags to output your information if the data to
> your second and third query is dependent upon the info from the first?
> here are my first 2 queries.
> <!--- Query to get all User's info. --->
> <cfquery name="qryAllEmp" datasource="ITData">
> SELECT * FROM tblEmployees
> WHERE
>   tblEmployees.FName LIKE '#fname#%'
> AND tblEmployees.LName LIKE '#lname#%'
> <cfif office eq "All Offices">
> AND tblEmployees.Office LIKE '%'
> <cfelse>
> AND tblEmployees.Office LIKE '#office#%'
> </cfif>
> ORDER BY tblEmployees.lname
> </cfquery>
> <!--- Query to get the users Equipment info. Setting iEquipID eq the
> previous query's results. --->
> <cfset iEquipID = qryAllEmp.EmpID>
> <cfquery name="qryEquipment" datasource="ITData">
> SELECT * from tblEquipment
> WHERE EquipID = #iEquipID#
> </cfquery>
> I want to be able to have one table that i can put the information all
> together.  any ideas?
>
>
> *************************************************
> This e-mail, including any attachments, is intended for the
> receipt and use by the intended addressee(s), and may contain
> confidential and privileged information.  If you are not an intended
> recipient of this e-mail, you are hereby notified that any unauthorized
> use or distribution of this e-mail is strictly prohibited.
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to