homepage Welcome to WebmasterWorld Guest from 54.198.148.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to Put Totals At The End Of A Summary
PHP total the summary
mcshanenoel




msg:4455292
 11:14 am on May 19, 2012 (gmt 0)

Hi
This is my first post so I hope the details given are adequate.

Can any one point in the right direction.

I am running a query to select summary data and would like to total that summary data at the end of the column.
What is the best way to do this?


result = mysql_query("SELECT nomcode,sum(debit),sum(credit) FROM nomledg


echo "<tr><td align=right>";
echo $row['nomcode'];
echo "</td><td align=right>";
echo number_format($row['sum(debit)'],2);
echo "</td> <td align=right>";
echo number_format($row['sum(credit)'],2);

echo "</td><td align=right>";
echo number_format($total=($row['sum(debit)']- $row['sum(credit)']),2)
echo "</td></tr>";

 

cffrost2




msg:4455406
 9:00 pm on May 19, 2012 (gmt 0)

Hi. Welcome aboard! There are a few different ways to do what you're wanting. One in which is like you're doing now. Is there an error with what you have now? Is what you're doing now not resulting how you need or are you just looking for "other ways" of accomplishing the same results?

mcshanenoel




msg:4455539
 10:58 am on May 20, 2012 (gmt 0)

Hi

Currently what I have shown is working fine, giving me four columns in a table.

What I would like to achieve is totals at the bottom of each of the summed columns.

At present I have a sum debit, sum credit, and a sum total,
I would appreciate some guidance on how to get totals of these summed columns and present them at the bottom of there respective columns.



Regards

Noel

coopster




msg:4460625
 10:55 pm on Jun 1, 2012 (gmt 0)

You need to initialize some variables to store the total values and then after your loop is complete and you have build the tables rows you write out one last table row of totals. Pseudocode ...


$debit = 0;
$credit = 0;
$total = 0;
while|for|foreach (<your loop that fetches and loads each MySQL row result here>) {
// MySQL get information ...
$debit += $row['sum(debit)'];
$credit += $row['sum(credit)'];
$total += $row['sum(debit)']- $row['sum(credit)'];
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved