Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  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. Similar Questions and Discussions

    1. 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...
    2. 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;...
    3. 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...
    4. 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...
    5. 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...
  3. #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

  4. #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

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139