[thelist] Totalling MySQL records in PHP
Alan McCoy
a.r.mccoy at larc.nasa.gov
Mon Aug 9 08:39:03 CDT 2004
Ah, don'tcha just hate it when you figure it out seconds after hitting the
send button...
Anyway, I just added a line to the 'while' loop that retrieves all the data:
$total_fees += $row['fee'];
Works quite nicely.
Thanks anyway, folks!
Alan
=> I'm trying to add up the total dollar amount from a column
=> of prices. I've thought about doing like the following:
=>
=> 1. Total the amounts in the MySQL query and then printing
=> the total like so,
=>
=> $result = mysql_query("SELECT a.agent, g.agent, g.gear, c.gear,
=> SUM(g.fee) AS total_fee FROM flpagnt AS a, flpgear AS g,
=> flpgrcde AS c WHERE a.agent = '01001' AND a.agent = g.agent
=> AND g.gear = c.gear");
=> $row = mysql_fetch_assoc($result);
=> echo "Total fees collected: ".$row['total_fee']."<br>";
=>
=> But this doesn't work for some reason. I get a
=> "mysql_fetch_assoc(): supplied argument is not a valid MySQL
=> result resource" error back.
=>
=> == OR ==
=>
=> 2. Use PHP to add up the total from an array of all the
=> collected data from that column ($row['fee'] for example).
=> That way I figure I can use one query for the whole thing
=> and just total things up using PHP. But I haven't been able
=> to find any code that shows how to do this.
=>
=> Any help with this would be greatly appreciated!
=>
=> Thanks!
=>
=> Alan
----------------------------------------
My Inbox is protected by SPAMfighter
5054 spam mails have been blocked so far.
Download free www.spamfighter.com today!
More information about the thelist
mailing list