Sorry, Jay, but that's a horrible method. You could just run one query with
a GROUP BY clause to get the sum for each invoiceID, instead of running
multiple queries like you've mentioned...
$query = SELECT invoiceid, SUM(partpaidamount) AS partpaid FROM $tb_name
GROUP BY invoiceid;
$rs =
[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
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
I think you're a big confused here. Your query will only return one row,
because you're using sum(). $invoicepartpaid will be your total for the
invoiceid specified.
-Original Message-
From: Ben C. [mailto:[EMAIL PROTECTED]
Sent: Monday, August 04, 2003 11:42 PM
To: [EMAIL PROTECTED]
[snip]
Sorry, Jay, but that's a horrible method. You could just run one query
with
a GROUP BY clause to get the sum for each invoiceID, instead of running
multiple queries like you've mentioned...
$query = SELECT invoiceid, SUM(partpaidamount) AS partpaid FROM
$tb_name
GROUP BY invoiceid;
$rs =
From bitter experience I'll suggest that it's a REALLY GOOD idea to store
invoice totals, subtotals, etc. in either the invoice header record. If not
rounding errors, or some small change in logic, can come back and bite you
- accountants get *really* upset when that 3000.00 invoice becomes
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 =
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
Yes, I know. However, the while() loop should generate all the invoice in a
list.
-Original Message-
From: Giz [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 05, 2003 12:03 AM
To: 'Ben C.'; [EMAIL PROTECTED]
Subject: RE: [PHP] Sum a column of values from a MySQL query
I think you're a
On Tuesday 05 August 2003 15:43, Ben C. wrote:
Yes, I know. However, the while() loop should generate all the invoice in
a list.
As has been pointed out the query only results in a single row. So how would
the while-loop generate all the invoice[s]? It's only ever given a single
row to play
[snip]
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;
[/snip]
That is what he is doing. The SELECT SUM will only return ONE row! I am
not sure that the problem is being explained clearly
-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
12 matches
Mail list logo