Quoting "Ben C." <[EMAIL PROTECTED]>: > 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.
Well, instead of doing $invoicepartpaid = $row['partpaid']; you could do $invoicepartpaid += $row['partpaid']; which will just add $row['partpaid'] to $invoicepartpaid, not replace it. However, why not just SUM all the rows in the table in the query if you just want a total? $sql_2 = "SELECT SUM(partpaidamount) as partpaid FROM $tb_name"; -- Adam Alkins http://www.rasadam.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php