Skip to main content
December 10, 2008
Question

Group by or Loop

  • December 10, 2008
  • 1 reply
  • 849 views
Hi Everyone,

I'm trying to generate the following output from an Access DB:

Desired Ouput:

<u>Minneapolis</u>
ND, SD -John ext 2240
IL- Charles ext 2222
MI, WI -Laurie ext1300
MN – Sara ext 4555

Here's the CF code i'm using:

<!---Minneapolis--->
<cfquery name="Minneapolis" datasource="cs_data">
SELECT responsibility.state_name, responsibility.state, admin.csr_name, admin.csr_extension,
admin.csr_first_name, admin.csr_extension, responsibility.reg_office
FROM admin, responsibility
WHERE responsibility.csr_id = admin.id AND responsibility.reg_office = 'Minneapolis'
ORDER BY admin.csr_name
</cfquery>

<table width="1000">
<tr>
<td valign="top" width="600"><cfloop query="Minneapolis">
<cfoutput><br>#state#&ndash;#csr_name# | Ext&ndash;#csr_extension#</cfoutput>
</cfloop></td>
</tr>
</table>

But instead of the desired output i'm getting the following output:

WI–Laurie | Ext–1300
SD–John | Ext–2240
ND–John | Ext–2240
MN–Sara | Ext–4555
MI–Laurie | Ext–1300
IL–Charles | Ext–2222

I just want the Person's name listed with all the states they're responsible for.

Would I use a group by to solve this? Any help would be appreciated.

thanks,


This topic has been closed for replies.

1 reply

Inspiring
December 10, 2008
Not group by, but the group attribute of cfoutput. Details are in the cfml reference manual. If you don't have one, the internet does.
December 10, 2008
thanks for the tip Dan. i did the following but it looks like it removed the rest of the states

<cfoutput query="Minneapolis" group="csr_name">
<br>#state#&ndash;#csr_name# | Ext&ndash;#csr_extension#</cfoutput>

Here's the output I'm getting:

WI–Laurie | Ext–1300
SD–John | Ext–2240
MN–Sara | Ext–4555
IL–Charles | Ext–2222

It's missing the rest of the states. Any thoughts???