Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
H3ath0r #1
Dynamic RecordCount
I am looping through a list of sites and counting the number of articles live
and pending. I'd like to be able to refer to the RecordCount for each. But
when I put hacks around the AbbrevLive.RecordCount variable, it doesn't work.
How do you call to a recordcount when the name of the query is a dynamic
variable?
CODE:
<cfquery name="BBIPsites" datasource="BBN">
SELECT *
FROM Sites
ORDER BY SiteName
</cfquery>
<cfloop query="BBIPsites">
<cfoutput>
<strong>#SiteName#</strong><br>
<cfquery name="#Abbrev#Pending" datasource="BBN">
SELECT ID FROM #TableName#
WHERE Author = #Session.AuthorID# AND LIVE = 0
</cfquery>
<cfquery name="#Abbrev#Live" datasource="BBN">
SELECT ID FROM #TableName#
WHERE Author = #Session.AuthorID# AND LIVE = 1
</cfquery>
The number of live articles on #SiteName# is #Abbrev#Live.RecordCount<br>
The number of pending articles on #SiteName# is #Abbrev#Pending.RecordCount<br>
<br>
</cfoutput></cfloop>
H3ath0r Guest
-
Indirect recordcount
I have a variable that contains the name of a query. How can I get the RecordCount for that query? I've tried using Evaluate() in several... -
Getting a recordcount
Hi I have opened a database in PHP and would like to know whether a particular record exists. i.e. $ThisUsername = $_REQUEST;... -
recordcount -1
I'm simply trying to get a number of records returned in a recordset, and just get a -1. I have looke din a few books and other references, can't... -
RecordCount Property and SQL
When using an access database, I could retrieve the recordcount with code below For r = 1 to RS.RecordCount When I try the same syntax on a... -
Why does the RecordCount property always = -1
I have a working set of data coming back from my database without any problems. I am trying to add a textbox to each row of repeated data and... -
mxstu #2
Re: Dynamic RecordCount
Use Evaluate()
<cfoutput> RecordCount: #Evaluate(Abbrev &"Live.RecordCount")# </cfoutput>
If you only need the total count, try using the COUNT() function. This avoids
retrieving records you don't need.
<cfquery name="#Abbrev#Live" datasource="yourDSN">
SELECT COUNT(ID) AS NumberOfLiveArticles
FROM YourTable
<!--- your where clause here ... --->
</cfquery>
<cfoutput>
Number of Live Articles: #Evaluate(Abbrev &"Live.NumberOfLiveArticles")#
</cfoutput>
mxstu Guest
-
H3ath0r #3
Re: Dynamic RecordCount
Both methods work great. Thanks so much for your suggestion to use the
Count() Function. That's a good idea. And I can use your other Evaluate
string in other instances where I'm looping through the data looking for things
other than the count.
H3ath0r Guest



Reply With Quote

