So I have a query that returns the following results in PHP, and I'm trying to add the total of the hours_played
, I have tried array_sum()
but that does not seem to work, I would like to be able to add the values of hours_played
to be 11 that way I can then pass that it another function :
Array
(
[id] => 1
[team_id] => 1
[hours_played] => 1
)
Array
(
[id] => 2
[team_id] => 1
[hours_played] => 4
)
Array
(
[id] => 3
[team_id] => 1
[hours_played] => 6
)
I'm a little bit lost and do I need to store the able Arrays in another array to be able to do this? The results above are from a sql query and is what is printed on the page when I print_r
the $row
variable.
$sql = "SELECT * FROM table1 WHERE team_id = 1";
$res = mysql_query($sql);
while($row = mysql_fetch_assoc($res)){
print_r($row);
}