What are you expecting back from the sql statement?

And what are you getting?

>From what I can tell, if you are getting all your amounts from the select
statement then you are already totalling them up inside the select
statements by using the sum() function call.

if you are wanting, or expecting, a row for each invoice, then you need to
remove the where clause and the sum() alias and then loop through the result
set and add partpaidamount to a empty variable.

also, I just noticed that you are using double quotes in your statement.  I
have always had bad luck with using double quotes.  I would switch to single
quotes.

how are you getting the $invoiceid value?  is this code inside another a
larger loop?

Jim lucas

----- Original Message -----
From: "Ben C." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, August 04, 2003 10:33 PM
Subject: 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----------------
>
> 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.
>
>
> --------------------------------------------------------------------------
> The content of this email message and any attachments are confidential and
> may be legally privileged, intended solely for the addressee.  If you are
> not the intended recipient, be advised that any use, dissemination,
> distribution, or copying of this e-mail is strictly prohibited.  If you
> receive this message in error, please notify the sender immediately by
reply
> email and destroy the message and its attachments.
>
>


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

Reply via email to