recordcount of a nested cfoutput ....

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

  1. #1

    Default recordcount of a nested cfoutput ....

    <cfoutput query='sqlGetAgents' group='areaName'> <h4>#areaName#</h4>
    <cfoutput group='agentID'> <p><strong>#agentName#</strong></p> </cfoutput>
    </cfoutput> how do i get the recordcount of the number of items within the
    nested cfoutput ? thanks

    Shaffer Guest

  2. Similar Questions and Discussions

    1. RecordCount & Grouping, I think?
      Hi all, I'm hoping someone here will be able to help me out with a little query that I've not been able to get working (and I've asked on two...
    2. recordCount property
      hi. i'm using Mach II to build my app but i have a question about the recordCount property of a query object. i'm performing login validation...
    3. 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...
    4. 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;...
    5. 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...
  3. #2

    Default Re: recordcount of a nested cfoutput ....

    You would have to do some counting yourself. There is no RecordCount for the
    nested grouped output, because it is really all the same query, CF is just
    doing a little formatting for you. You are going to have to set a variable for
    the "areaName" and see if it is different than the previous row...if it is,
    start a counter for the inner loop until that areaName changes again.



    blewis Guest

  4. #3

    Default Re: recordcount of a nested cfoutput ....

    Well, if that's what you really want in the cfoutput then:

    Select distinct areaname, agentname from sometable order by areaname

    would give you the same results, and RecordCount would be equal to the
    nested number of items.

    OldCFer Guest

  5. #4

    Default Re: recordcount of a nested cfoutput ....

    ok, Let me see if i can explain a little better: We have a query that gets
    countrys and agents that belong to that country...we want to display the
    country and the details for each agent that belongs to that country.....we need
    to know the number of agents that belong to each country (hope you with me so
    far) the sql i have for this is as follows: (btw, using mysql 4.0) <cfquery
    name='sqlGetAgents' datasource='#Application.dsn#'> SELECT
    agent_areas.agent_area_id, agents.agent_id AS agentID, agents.agent_name AS
    agentName, agents.agent_address AS agentAddress, agents.agent_telephone_no AS
    agentTelNo, agents.agent_fax_no AS agentFaxNo, agents.agent_email_address AS
    agentEmail, agent_areas.agent_area_name AS areaName FROM agents, agent_areas,
    agent_regions, agent_divisions, product_divisions WHERE
    agent_regions.agent_region_id = #url.id# AND agent_areas.agent_area_id =
    agents.agent_area_id AND agent_regions.agent_region_id =
    agent_areas.agent_region_id AND agents.agent_id = agent_divisions.agent_id AND
    product_divisions.product_division_id = agent_divisions.product_division_id AND
    agent_divisions.product_division_id = #url.did# <!--- did = Division ID Passed
    from product_detail.cfm ---> ORDER BY agent_areas.agent_area_id DESC,
    agents.agent_name </cfquery> and this is the code for the output:
    <cfoutput query='sqlGetAgents' group='areaName'> <h4>#areaName#</h4> <cfoutput
    group='agentID'> <p><strong>#agentName#</strong></p> </cfoutput> </cfoutput>
    in the second cfoutput i want to put something like: <cfif noOfAgents GT 1>Do
    this</cfif> <cfif agent.currentRow EQ noOfAgents - 1>do this </cfif> hope that
    makes sense i've tried putting COUNT within my query: eg: select
    count(agentName) as total from tableName where bla bla bla, but it wont
    work....because it will only return the total no of records, not the ones
    within the nested cfoutput also tried sql count on group by, but that gets rid
    of some results that we need to return... any ideas ? thanks shafiq :sK

    Shaffer Guest

  6. #5

    Default Re: recordcount of a nested cfoutput ....

    Hi Shaffer

    Attached code shows the count that you need to add to your existing code. Have
    also shown an alternate method which will produce the same outcome.

    I haven't looked too closely at your query but will it retrieve the areas that
    have no agents in them?? It doesn't look like it as you aren't using OUTER
    JOINS at all. When joining to the agents table you'd need to do a LEFT OUTER
    JOIN to also retrieve the areas that don't have any agents setup.
    (NB. alternate code will not have a proble with areas that have not agents
    setup)

    Hope this helps.

    Zoe

    <!--- loop over query grouped by area name --->
    <cfoutput query="sqlGetAgents" group="areaName">

    <h4>#areaName#</h4>

    <!--- set/reset agent Counter ---->
    <CFSET agentCount = 0>

    <cfoutput group="agentID">
    <CFSET agentCount = agentCount + 1>
    #agentName#
    </cfoutput>

    <!--- agentCount will be the recordCount for the area --->
    <CFIF agentCount GT 1>
    Do this
    </CFIF>

    </cfoutput>


    alternative

    <!--- get all areas --->
    <CFQUERY NAME="getAreas">
    select * from agent_areas
    </CFQUERY>

    <!--- get all agents --->
    <CFQUERY NAME="getAllAgents">
    select * from agents
    </CFQUERY>


    <!--- loop over areas --->
    <CFLOOP QUERY="getAreas">

    <!--- get agents for the current area - using QoQ --->
    <CFQUERY NAME="getAreaAgents">
    SELECT *
    FROM getAllAgents
    WHERE Area = #AreaID#
    </CFQUERY>

    <CFIF getAreaAgents.RecordCount GT 0>
    <!---- loop over agents for the area --->
    <CFLOOP QUERY="getAreaAgents">
    #agentName
    </CFLOOP>
    <CFELSE>
    No Agents for this Area!!
    </CFIF>

    </CFLOOP>

    zoeski80 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