Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Cfoutput issues

New Here ,
Aug 06, 2009 Aug 06, 2009

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>

635
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 06, 2009 Aug 06, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 06, 2009 Aug 06, 2009

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 06, 2009 Aug 06, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources