Tried sending this earlier but it returned undeliverable > -----Original Message----- > From: Dave Wilson [mailto:[EMAIL PROTECTED]] > Sent: 05 December 2001 17:50 > To: [EMAIL PROTECTED] > Subject: RE: Stumped: Getting recordcount for dynamic query within a > cfloop > > > Paul, > > ColdFusion is unable to parse correctly a variable statement such > as #variablename#.recordcount. What you need to do is use the > Evaluate function to do this. > > Now before explaining how to do the evaluate, may I suggest you > do everything within step 1, like this: > > <!--- no need for cfloop as cfoutput can do same thing ---> > <cfoutput query="categories" group="newsletterid"> > <!--- No need to assign separate query names. Use a static name > for query ---> > <cfquery name=queryname datasource="my_dsn"> > select * > from newsletterItems > where newsletterID = #newsletterid# and newsletterHeadingID = > #newsletterheadingid# > </cfquery> > <!--- Now do your step 2 stuff here ---> > > <cfif "queryName.recordcount" gte 1> DO THIS </cfif> > <cfif "queryName.recordcount" lt 1> DO THAT </cfif> > > </cfoutput> > > > Now, if for some reason this will not work for you (maybe your > steps need to be separated for other reasons?) then you could > look at the Evaluate function like below: > > <CFIF Evaluate("#queryName#.recordcount") GT 0> > > HTH, > Dave > > > -----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 > > > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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

