Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding total to bottom of table 2

Status
Not open for further replies.

shamrox7

Programmer
Aug 1, 2007
14
US
I have a table that I output data in from a mysql query. I'd like to show a total of one column but I'm not sure how this should be written. Any help?
 
It could be somethng as simple as:
Code:
</table>
<?PHP
echo $total_of_columnx;

?>

Can you explain in a bit more detail how you get the total, and where in relation to the table the total should be etc...?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
column would be $saleprice
last row would have Totals: and under the saleprice column, I'd want a total of all the saleprices listed.
 
and within your loop for outputting the rows, use the following to create the totals
Code:
$col = '';//enter column name
$total = 0;
while ($row = mysql_fetch_assoc($result)){
  $total = $total + $row[$col];
  //output row
}
//follow vacunita's instructions
 
Hello shamrox7,

You can also make a sql statement:

select sum(saleprice) as sum_saleprice from tble_sales

sum_saleprice gives the total amount!

Solo1234.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top