Skip to main content
BreakawayPaul
Inspiring
May 3, 2012
Question

Problems with cfoutput and grouping

  • May 3, 2012
  • 1 reply
  • 3193 views

I'm trying to build a back-end editing page for a web app that we have.  It's basically a search tool where you put in some criteria, and it gives you results in the form of resources with URLs.

The web app in question lives here: http://www.fhwa.dot.gov/real_estate/practitioners/rcb_navigator/

You start by choosing your role, then picking your resource type, then your competency area, then your level of understanding (noob, expert, or in-between).

Each resource has one type (first step), and a fixed level of understanding (last step), but it can have many roles or areas.

The back-end page I'm building is basically a form that gets filled out by a query, and that you will eventually be able to make changes to and submit.  On the page is a bulleted list of roles, and another one for areas, and that's what I'm having problems with.  The first bulleted list displays fine, but the second one repeats for the number of entries in the first.  So, for instance if there are 3 roles and 4 areas, each of the 4 areas repeat 3 times.

I have been fiddling with it all morning, and I'm sure it's something stupid.  Here's what I have:

Query:

<cfquery name="navedit" datasource="navigator">

SELECT       resources.resource_id

        , resources.resource_title

        , resources.resource_type

        , resources.resource_url

        , resources.resource_url_exit

        , resources.resource_desc

        , resources.resource_provider

        , resources.provider_url

        , resources.provider_url_exit

        , resources.resource_roles

        , resources.resource_level

        , types.type_id

        , types.type_name

        , roles.role_id

        , roles.role_name

        , areas.area_id

        , areas.area_name

FROM ( ( ( ( ( resources

INNER JOIN types

        ON resources.resource_type = types.type_id

        )

INNER JOIN resc_roles

        ON resc_roles.rr_resource_id = resources.resource_id

        )

LEFT JOIN roles

        ON roles.role_id = resc_roles.rr_role_id

        )

INNER JOIN resc_areas

        ON resc_areas.ra_resc_id = resources.resource_id

        )

LEFT JOIN areas

        ON areas.area_id = resc_areas.ra_area_id

        )

WHERE resource_id = <cfqueryparam value="#URL.id#" cfsqltype="cf_sql_numeric">

</cfquery>

And here's the form:

<cfform name="edit_resc" method="post" action="navedit.cfm">

<table border="0" cellspacing="5">

<tr>

<td><label for="resourcetitle">Resource Title:</label></td>

<td><cfinput type="text" class="cf_textinput" name="resourcetitle" size="70" value="#navedit.resource_title#" /></td>

</tr>

<tr>

<td><label for="resourceurl">Resource URL:</label></td>

<td><cfinput type="text" class="cf_textinput" name="resourceurl" size="110" value="#navedit.resource_url#" /><input type="checkbox" class="cf_textinput" name="resourceurlexit" id="resourceurlexit"<cfif navedit.resource_url_exit eq 1> checked="checked"</cfif> /><label for="resourceurlexit">Exit Door</label></td>

</tr>

<tr>

<td><label for="resourceprovider">Resource Provider:</label></td>

<td><cfinput type="text" class="cf_textinput" name="resourceprovider" size="70" value="#navedit.resource_provider#" /></td>

</tr>

<tr>

<td><label for="provider_url">Resource Provider URL:</label></td>

<td><cfinput type="text" class="cf_textinput" name="provider_url" size="110" value="#navedit.provider_url#" /><input type="checkbox" class="cf_textinput" name="providerurlexit" id="providerurlexit"<cfif navedit.provider_url_exit eq 1> checked="checked"</cfif> /><label for="providerurlexit">Exit Door</label></td>

</tr>

<tr>

<td><label for="resourcetype">Resource Type:</label></td>

<td>

<select name="resourcetype" id="resourcetype">

<cfoutput query="list_types"><option value="#type_id#"<cfif type_id eq navedit.type_id> selected="selected"</cfif>>#type_name#</option>

</cfoutput>

</select></td>

</tr>

<tr>

<td valign="top"><label for="pickroles">Roles:</label></td>

<td valign="top">

<ul>

<cfoutput query="navedit" group="role_id"><li>#role_name# <a href="navedit.cfm?delrole=#role_id#&resc=#resource_id#">X</a></li></cfoutput>

</ul>

<select name="pickroles" id="pickroles">

<cfoutput query="addroles"><option value="#role_id#">#role_name#</option>

</cfoutput>

</select>

<input type="submit" name="submitrole" value="add" /></td>

</tr>

<tr>

<td valign="top"><label for="pickareas">Areas:</td>

<td valign="top">

<ul>

<cfoutput query="navedit" group="area_id"><li>#area_name# <a href="navedit.cfm?delarea=#area_id#&resc=#resource_id#">X</a></li></cfoutput>

</ul>

<select name="pickareas" id="pickareas">

<cfoutput query="addareas"><option value="#area_id#">#area_name#</option>

</cfoutput>

</select>

<input type="submit" name="submitarea" value="add" /></td>

</tr>

<tr>

<td colspan="2" valign="top"><hr /></td>

</tr>

<tr>

<td colspan="2" align="center" valign="top"><input type="submit" name="submitall" value="Done" /></td>

</tr>

</table>

</cfform>

I need to figure out how to stop the second bulleted list from repeating.  Any ideas?

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 3, 2012

    the syntax for grouping is:

    <cfoutput query="myQuery" group="column1">

         #column1#

         <cfoutput group="column2">

              #column2#

         </cfoutput>

    </cfoutput>

    BreakawayPaul
    Inspiring
    May 3, 2012

    Yes, that's the easy part.  But when I have a third group, that's when it gets tricky.

    Using your example, I created this:

    <cfoutput query="navedit" group="resource_id">

    <p>#resource_title#</p>

    <p>Roles:</p>

    <ul>

    <cfoutput group="role_id">

    <li>#role_name#</li>

    </cfoutput>

    </ul>

    <p>Areas</p>

    <ul>

    <cfoutput group="area_id">

    <li>#area_name#</li>

    </cfoutput>

    </ul>

    </cfoutput>

    Which gave me this:

    International Right of Way Association (IRWA)

    Roles:

    • Acquisition Agent
    • Appraiser
    • Relocation Agent

    Areas

    • Access Control
    • Negotiation Skills
    • Right-of-Way Engineering
    • Access Control
    • Negotiation Skills
    • Right-of-Way Engineering
    • Access Control
    • Negotiation Skills
    • Right-of-Way Engineering

    Each of the Areas in the second group are repeated x times, where x is the number of items in the first group.

    I also tried specifying role_id and area_id in the ORDER BY clause with no improvement.

    Inspiring
    May 3, 2012

    if for each role you can have several areas, just nest that one too, like:

    <cfoutput query="myQuery" group="column1">

         #column1#

         <cfoutput group="column2">

              #column2#

              <cfoutput group="column3">

                   #column3#

              </cfoutput>

         </cfoutput>

    </cfoutput>