Array_sum does not work as expected pq mysql_query()
returns only a row and not the entire array, for example:
SELECT valor FROM tabela
will be returned to line:
Array
(
[0] => 150
[valor] => 150
)
When applied the array_sum the result will be 300 because it is summing the value of the two keys and also pq $soma_das_visu
is overwritten every time while.
Depending on how is your query the answer from @Leandro Curious is the most practical. Or you can use a variable to save the total:
$total = 0;
while ($rows = mysql_fetch_array($searc)) {
$total += $rows['valor'];
}
echo 'total: '+ total;
Try to add the right key values:
$total= 0;
while(....){
$total += $rows['valor']
– rray