0
I am using this function to search for a field in a table:
function rendimentoDia($conexao, $dia) {
$rendimentos = array();
$resultado = mysqli_query($conexao, "select valor from hospedes where dia =
$dia");
while($rendimento = mysqli_fetch_assoc($resultado)) {
array_push($rendimentos, $rendimento);
}
return $rendimentos;
}
then I use this code to display the data on the screen:
<table class="container">
<?php
$rendimentos = rendimentoDia($conexao, $dia);
foreach($rendimentos as $rendimento) :
?>
<tr>
<td><?= $rendimento['valor']?></td>
</tr>
<?php
endforeach
?>
</table>
This field brings the values entered in a day, I would like to add these values and I am not getting, I tried to add using array_sum in a variable that saved the value yield, but it did not work.. the function is bringing everything right and displaying, I just can’t add even. I thank anyone who can help
If you do the direct sum in SQL that brings the information not right ? For example, do the following:
select SUM(valor) from hospedes where dia = 
$dia
– Leo
You need all the separate values as well or just the sum?
– Woss
hello Anderson, I will try here by mysql, I just need the same result, thanks
– Francis Vagner da Luz