Sum a column of values from a MySQL query

From: Date: Tue, 05 Aug 2003 06:42:14 +0000
Subject: Sum a column of values from a MySQL query
Groups: php.general 
Request: Send a blank email to php-general+get-158244@lists.php.net to get a copy of this message
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---------------- 1) The code returns the sum of a partially paid invoice. The individual invoice is 'partpaid'. WORKS...NO PROBLEM 2) The while() then return a list of partially paid invoices which is $invoicepartpaid. WORKS..NO PROBLEM 3) I then want to add the list of partially paid invoices ($invoicepartpaid) together. I AM STUCK HERE ADDING THE INVOICES AMOUNTS TOGETHER. If anyone can help I would greatly appreciate it.

« previous php.general (#158244) next »