CFQUERY is allowed in any type of CFLOOP so the addition of CFOUTPUTs into
the loop is irrelevant.
This thread reminded me of a BUG in CF which I can confirm is still in CF5RC
(haven't checked with the final release yet but I doubt it has changed!)
which concerns the nesting of query driven loops that I thought I'd post as
I doubt everyone is aware of it. Let's say we have 2 query loops (named
query1 and query2 for simplicity), in which for each record in query1,
query2 is iterated over fully. Now, if within the query2 loop you refer to
query1.somefieldname you would expect it to contain the value of the record
that query1 is currently on. But no. It always contains the value of the
FIRST record in query1. The workaround is to initialise a local variable
before entering into the inner loop and from within the loop refer to the
local variable.
<cfloop query="query1">
<cfloop query="query2">
<!--- The following line will output the value of somevarname for the
first record in query1--->
<cfoutput>#query1.somevarname#</cfoutput><br>
</cfloop>
</cfloop>
<cfloop query="query1">
<cfset someLocalVarname = query1.somevarname>
<cfloop query="query2">
<!--- This works like the above should!!! --->
<cfoutput>#variables.someLocalVarname#</cfoutput><br>
</cfloop>
</cfloop>
Steve
> -----Original Message-----
> From: Bill Davidson [mailto:[EMAIL PROTECTED]]
> Sent: 31 May 2001 18:06
> To: CF-Talk
> Subject: Re: Is it possible to nest CFQUERY inside CFLOOP?
>
>
> You should be able to nest cfquery in a cfloop that is not query based...
> Maybe the actual problem is that cfloop doesn't implicitly force
> a cfoutput,
> so chances are your variables are not getting resolved. Include a
> <cfoutput> inside the loop.
>
> Here's a code snippet where I am nesting a query inside a loop:
> <cfloop index="loop_index" from="1" to="#ArrayLen(jobs_time_spent)#">
> <cfoutput>
>
> <CFQUERY name="qry_job_rate" datasource="#application.dsn#">
>
> SELECT dbo.Jobs.Jobs_Job_Name, dbo.Employee_Job_Rates.*
> FROM {oj dbo.Jobs LEFT OUTER JOIN dbo.Employee_Job_Rates ON
> dbo.Jobs.Jobs_ID = dbo.Employee_Job_Rates.Employee_job_rates_job_id }
> where Employee_job_rates_employee_id = #attributes.user_id#
> and dbo.Jobs.Jobs_Job_Name = '#jobs_names[loop_index]#'
>
> </CFQUERY>
> .....
> </cfoutput>
> </cfloop>
>
> The only other thing I could think of is the list attribute for cfloop.
> Maybe cold fusion internally handles lists as a query. Maybe just do a
> "from to" loop and only do the query and related code when the index is in
> the list. That's what I am doing in the previous block of code,
> except with
> arrays.
>
> HTH,
> -Bill
> www.brainbox.tv
>
> ----- Original Message -----
> From: "Kevin Gilchrist" <[EMAIL PROTECTED]>
> To: "CF-Talk" <[EMAIL PROTECTED]>
> Sent: Thursday, May 31, 2001 11:38 AM
> Subject: FW: Is it possible to nest CFQUERY inside CFLOOP?
>
>
> > I just noticed the loop index variable is wrong, I changed it
> to from "i"
> to
> > "region" as it should be and still got the same error message...
> >
> > -----Original Message-----
> > From: Kevin Gilchrist
> > Sent: Thursday, May 31, 2001 11:32 AM
> > To: CF-Talk (E-mail)
> > Subject: Is it possible to nest CFQUERY inside CFLOOP?
> >
> >
> > I get an error when I try to do this:
> >
> > <cfloop index="region" list="lst_region">
> > <cfquery name="qry_Full_Week_Downtime_Region#i#" datasource="#DSN#"
> > dbtype="Oracle80" cachedwithin="#CreateTimeSpan(0,1, 0, 0)#">
> > SELECT
> > sum(severity_minutes) as sev_sum,
> > max(total_minutes)
> > FROM
> > history_view,
> > site_name
> > WHERE
> > query_id =259 AND
> > node='RS_CHARMING1' AND
> > severity=5 AND
> > customer_name='CHARMING' AND
> > application='RS_PING' AND
> > region=#i#
> > </cfquery>
> > </cfloop>
> >
> > The error message is:
> >
> > Just in time compilation error
> > A nested CFQUERY tag has been encountered at document position
> (455:2) to
> > (455:130). CFQuery tags cannot be nested inside one another.
> >
> >
> >
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists