Number of Live Articles: #Evaluate(Abbrev &"Live.NumberOfLiveArticles")# [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => mxstu [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Dynamic RecordCount - Coldfusion - Advanced Techniques

Dynamic RecordCount - Coldfusion - Advanced Techniques

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 = ...

  1. #1

    Default 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

  2. #2

    Default 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

  3. #3

    Default 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

Similar Threads

  1. RecordCount & Grouping, I think?
    By neilsytner in forum Coldfusion Database Access
    Replies: 6
    Last Post: June 28th, 10:55 AM
  2. Indirect recordcount
    By a440guy in forum Macromedia ColdFusion
    Replies: 4
    Last Post: May 13th, 01:42 PM
  3. Getting a recordcount
    By Andy Levy in forum PHP Development
    Replies: 3
    Last Post: October 29th, 08:55 AM
  4. recordcount -1
    By middletree in forum ASP
    Replies: 8
    Last Post: October 16th, 02:06 PM
  5. Why does the RecordCount property always = -1
    By George Mizzell in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 13th, 01:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •