RE: [PHP] Sum a column of values from a MySQL query
| From: | Giz | Date: | Tue, 05 Aug 2003 07:03:16 +0000 |
| Subject: | RE: [PHP] Sum a column of values from a MySQL query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158247@lists.php.net to get a copy of this message | ||
I think you're a big confused here. Your query will only return one row,
because you're using sum(). $invoicepartpaid will be your total for the
invoiceid specified.
-----Original Message-----
From: Ben C. [mailto:benc@cox.net]
Sent: Monday, August 04, 2003 11:42 PM
To: php-general@lists.php.net
Subject: [PHP] Sum a column of values from a MySQL query
I am trying to sum a query of values from a MySQL table. The code I am
using is:
---BEGIN CODE #1--------------
$sql_2 = "SELECT SUM(partpaidamount) as partpaid
FROM $tb_name
WHERE invoiceid = \"$invoiceid\"
";
$result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());
while ($row = mysql_fetch_array($result_2)) {
$invoicepartpaid = $row['partpaid'];
}
---END CODE #2----------------