PDA

View Full Version : Just a quick PHP question....



LMS16
10-08-2010, 09:53 AM
Hey,

How would I go about adding the values of a field fetched from a database?

Example:

I fetch all `total` fields from a table so I have:

450
560
ect...

How would I add every value together?

450+560

I want to be able to add the values together as I know they will be numeric.

Thanks.

Lew.

Jamesy
10-08-2010, 10:35 AM
you could use the SQL sum function: http://www.techonthenet.com/sql/sum.php

LMS16
10-08-2010, 03:57 PM
I got it working :)

Needed to do this:



$carTotalyone = mysql_fetch_array(mysql_query("SELECT SUM(totalCost) AS 'totalC' FROM totals WHERE carID=$ided AND totalYear=1"));

echo $carTotalyone['totalC'];

Want to hide these adverts? Register an account for free!