Solved

How to display summary fields

Posted on 2011-03-17
3
268 Views
Last Modified: 2012-05-11
I can display my data as format below:

Area      Cost 1      Cost 2
A           2              2
A           1              3
B           0              1
B           1              1

How can I display like below?

Area      Cost 1      Cost 2
A           2              2
A           1              3
A Total   3               5

B           0              1
B           1              1
B Total   1              2

it won't work with the code below:

<CFQUERY name="AreaCount">
    SELECT Area,Cost1, Cost2
    FROM Table1
</CFQUERY>


<cfoutput>
      
   <table>
     <tr>
        <td>Area</td>
      <td>Cost 1</td>
      <td>Cost 2</td>
     </tr>

     <cfloop query="AreaCount">

       <tr>
         <td>#Area#</td>
       <td>#Cost1#</td>
       <td>#Cost2#</td>
       </tr>
     
        <!---here is where I want to show total of area--->

    <CFQUERY dbtype="query" name="GetTotal">
     SELECT Area,sum(cost1) as C1_Total, sum(cost2) as c2_Total
     FROM AreaCount
     where area=#area#
     GROUP BY Area
    </CFQUERY>

     <tr>
         <td>Total</td>
       <td>#GetTotal.C1_Total#</td>
       <td>#GetTotal.c2_Total#</td>
       </tr


     </cfloop>

   
     
   
   </table>

</cfoutput>

thanks for helps.
0
Comment
Question by:pdd1lan
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 35156528
Use a group by in your cfouput loop and sub the values...
<CFQUERY name="AreaCount">
    SELECT Area,Cost1, Cost2
    FROM Table1
</CFQUERY>


      
   <table>
     <tr>
      <td>Area</td>
      <td>Cost 1</td>
      <td>Cost 2</td>
     </tr>

   <cfoutput query="AreaCount" group="area">
     <cfset variables.C1_subTotal = 0>
     <cfset variables.C2_subTotal = 0>

     <cfoutput>
     <tr>
       <td>#Area#</td>
       <td>#Cost1#</td>
       <td>#Cost2#</td>
     </tr>
      
       <cfset variables.C1_subTotal = variables.C1_subTotal + AreaCount.Cost1>
       <cfset variables.C2_subTotal = variables.C2_subTotal + AreaCount.Cost2>
     </cfoutput>
     <tr>
       <td>Total</td>
       <td>#variables.C1_subTotal#</td>
       <td>#variables.c2_subTotal#</td>
     </tr>
   </cfoutput>
   
   </table>

Open in new window

0
 
LVL 8

Author Comment

by:pdd1lan
ID: 35156817
it works. thanks.
0
 
LVL 8

Author Closing Comment

by:pdd1lan
ID: 35156823
good job
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now