RE: [PHP] Sum a column of values from a MySQL query
| From: | Jay Blanchard | Date: | Tue, 05 Aug 2003 12:45:46 +0000 |
| Subject: | RE: [PHP] Sum a column of values from a MySQL query | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-158270@lists.php.net to get a copy of this message | ||
[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 = mysql_query($query) or die(mysql_error());
while($r = mysql_fetch_assoc($rs))
{ echo "Invoice: {$r['invoiceid']}, SUM: {$r['partpaid']}"; }
---John Holmes...
PS: Sorry for the top post, but I'm at work and outlook express sucks.
:)
[/snip]
No problem bro'. I knew it was the long way around I was trying to
understand if that was what Ben wanted. And I am so old school that
almost always avoid ternary! :) And I feel for you....Express...blech!