Copy link to clipboard
Copied
Here's the cfquery that I have. It combines 2 tables (orders and users) and outputs required info. The problem that I have is the following.
For example, John Smith ordered 1 CD and 1 Book. The way this info is being displayed is:
1.John Smith - 1 CD
2.John Smith - 1 Book
How do I combine all orders that John Smith placed on one line, so it looks like that:
John Smith - 1 CD, 1 Book.
<cfquery datasource="#DATASOURCE#" name="xml">
SELECT
orders.date_ordered, users.id, users.firstname, users.lastname,users.organization,users.address1,users.address2,users.city,
users.state,users.zipcode,users.country,users.phonenumber,users.email,users.mailcode,orders.Quantity,orders.itemName,orders.item_lang,orders.SKU,
orders.itemid, orders.userid,orders.item_lang
FROM orders
LEFT OUTER JOIN users
ON users.id = orders.userid
WHERE orders.userid = users.id
</cfquery>
<cfoutput query="xml">
<p><strong>#DateFormat(date_ordered, "mm/dd/yyyy")#</strong> -
#firstname#
#lastname# -
#Quantity#
#itemName# </p>
<hr />
</cfoutput>
Copy link to clipboard
Copied
The group parameter of the cfoutput tag.
<cfoutput query="xml" group="lastname">
<p><strong>#DateFormat(date_ordered, "mm/dd/yyyy")#</strong> -
#firstname#
#lastname# -
<cfoutput>
#Quantity#
#itemName#
</cfoutput>
</p>
<hr />
</cfoutput>
The documentation explains this in more detail.
Copy link to clipboard
Copied
OMG! IIt worked! can't belive that that was it! I thought that the code needs to have cfloop or arrays in it!!!
You have no idea how appretiative I am of what you've done!
Thanks allot, Ian!
Copy link to clipboard
Copied
To ensure consistent results, the query should be ordered by the same fields the output is "grouping" by
ie ORDER BY LastName , .. then any other columns...