View Full Version : adding mysql results

05-06-2004, 01:46 AM
i have a query that selects rows from a db and i need it to add the prices together in the database and then output them for the Totals: section. is there a function that does this?

05-06-2004, 04:11 AM
while ($thisrow = mysql_fetch_array($result)) {
$total =+ $thisrow['cost'];

05-06-2004, 08:34 AM
if you only need the totals (so if you don't print out the individual records) then doit in sql. Like

SELECT sum(cost) as totalcast, productID FROM table GROUP BY productID

you can then acces the total for each 'productID' (or whatever variable your grouping on) with $row['totalcost']
if you leave off the GROUP BY clause and remove the productID from the fieldslist, then you get the total of all records.