[snip]
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.
[/snip]

Ben...do you want to add together invoices where each ID is different?
Is that right? If so I have the answer! You need to loop through the
ID's which you are not doing....I have taken your code and added to
it....(and made changes for clarity in the e-amil)

//get invoice id's
$sql_1 = "SELECT DISTINCT(invoiceid) as inid FROM $tb_name ";
$result_1 = mysql_query($sql_1, $connection) or die(mysql_error());

while($idinvoice = mysql_fetch_array($result_1)){
     // get partial paid for THIS invoice
     $sql_2 = "SELECT SUM(partpaidamount) as partpaid   ";
     $sql_2 .= "FROM $tb_name ";
     $sql_2 .= "WHERE invoiceid = '" . $idinvoice['inid'] . "' ";
     $result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());
     //you will only be returning ONE row, so no need for while loop
     $row = mysql_fetch_array($result_2);
     $invoicepartpaid = $row['partpaid'];
     $total = $total + $invoicepartpaid;
} // loop to NEXT invoice

print(number_format($total, 2, '', ','). "\n");

Does this make sense? You must loop through each ID and query for that
ID's partial amount.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to