Solved

calculating total in Dreamweaver mysql php

Posted on 2004-10-09
3
2,295 Views
Last Modified: 2011-10-03
I have a field "amount" and display many records (with  a repeat region)  I want to be able to add up all the total of the "amount" for all the records and put the total at the bottom.

I would be really grateful for any help here.
0
Comment
Question by:debbieau1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:alexhogan
ID: 12269125
You can do this in your SQL query;

SELECT sum(amount) as Total
FROM mytable

Your php code would look something like this;

$query = "SELECT amount, sum(amount) as Total
               FROM mytable";
$result = mysql_query($result) or die($err_msg);

while($row = mysql_fetch_array($result)){
    $amount = $row['amount'];
    $total     = $row['Total'];

    print .....

}
0
 
LVL 23

Accepted Solution

by:
Saqib Khan earned 125 total points
ID: 12280006
Should be...

$query = "SELECT amount, sum(amount) as Total
               FROM mytable Group by amount";
0
 
LVL 1

Author Comment

by:debbieau1
ID: 12281380
This worked well thanks a lot.  I had worked out to use the sum, but was grouping on the wrong field.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

707 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