$query = $db->query("SELECT * FROM orders");
while ($row = mysql_fetch_array($query)) {
$cost= array_sum($row['cost']);
}
This is not working, I want to to calculate the sum of all elements but I get this error:
Warning: array_sum() expects parameter 1 to be array, string given in C:\xampp\htdocs\falco\classes\controller.php on line 303
Any idea how to calculate all the elements coming from mysql?
Thank you for your time and help.
cost. The answers provided below are reasonable options, especially theselect sum(cost) from foo...mysql statement