The array_sum does not work as expected because mysql_query()
returns only one row and not the entire array, for example:
SELECT valor FROM tabela
will be returned to line :
Array
(
[0] => 150
[valor] => 150
)
When applied to the array_sum the result will be 300 because it is adding the value of the two keys and also pq $soma_das_visu
is overwritten with every loop of the while.
Depending on how your query is, the response from @Leandro Curioso 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;