> -----Original Message----- > From: Ben C. [mailto:[EMAIL PROTECTED] > Sent: 05 August 2003 07:42 > > 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
That's a very confusing description -- what do you mean by "sum of a partially paid invoce"? What you're getting is the sum of partpaidamount for all invoices with the given invoiceid -- although how you can have more than one invoice with the same invoiceid beats me! > 2) The while() then return a list of partially paid invoices which is > $invoicepartpaid. WORKS..NO PROBLEM No, wrong -- it can't and doesn't return a list, since the query above will return a *single* value -- the sum of partpaidamount for the selected invoices. That's one row with one value in it. > 3) I then want to add the list of partially paid invoices > ($invoicepartpaid) > together. I AM STUCK HERE ADDING THE INVOICES AMOUNTS TOGETHER. But you've already added the partially paid invoice amount together with your "SELECT SUM(partpaidamount) -- why are you trying to do it again? There seems to be a fundamental problem here somewhere -- why don't you go right back to the beginning and describe: (1) The table you are selecting from (fieldnames, what they contain, etc.). (2) Exactly what you are trying to extract from it, using what criteria. (3) Which exact values from that you want to add together. (4) and what you expect the final result to be. Then we might all be starting from a level playing field in terms of understanding exactly what you're trying to do (and if not, someone will be sure to ask further questions!). Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php