To do what you want to do you will need to use the Evaluate function... 

Ie

<CFIF Evaluate("#queryName#.recordcount") GT 0> etc

        



-----Original Message-----
From: Paul Sinclair [mailto:[EMAIL PROTECTED]] 
Sent: 05 December 2001 17:30
To: CF-Talk
Subject: Stumped: Getting recordcount for dynamic query within a cfloop


I have a cfapp that is working fine except for one small item and I
can't figure out how to handle this piece of it. Simplest way to
describe the issue is probably to describe the two steps involved that
are giving me a problem.

1. Step 1

This actually is not the problem area. What is done in the following
query cfloop is pretty simple - it just takes the results of an earlier
query, and then generates a series of new queries with the query names
based on a field from the earlier query.

<cfloop query="categories">

<cfoutput>
<cfset queryname = "#column_from_query#">
<cfquery name=#queryname# datasource="my_dsn">
select *
from newsletterItems
where newsletterID = #newsletterid# and newsletterHeadingID =
#newsletterheadingid# </cfquery> </cfoutput>

</cfloop>

After this code runs, I've got a series of 6 queries with names like
query1, query2, query3, query4, query5, query6.


2. Step 2

This is where I'm stumped. I want to loop through the same query as in
Step 1 ("categories") and then get an output of how many records were
returned for each query. So for "query1", how many records were found;
for "query2", how many records found; etc. If recordcount is 0, one
thing happens; if recordcount is not 0, another thing happens.

What is baffling me is how I put together the names of the dynamic
queries (query1, query2, etc.) with the recordcount function so that I
will get the count? I've tried all sorts of combinations of hash signs,
quote signs, etc. but none is working. Here's the latest version, which
does not work. It is the sequence at lines 06 and 07 below that are the
problem.

01 <cfloop query="categories">
02 <cfset queryName="#column_from_query#">
03
04 <cfoutput>
05
06 <cfif "#queryName#.recordcount" gte 1> DO THIS </cfif>
07 <cfif "#queryName#.recordcount" lt 1>  DO THAT </cfif>
08
09 </cfoutput>
10 </cfloop>

Thanks for any help.

Regards,
Paul Sinclair




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.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