4
Good evening friends, what is the correct way to add up these two fields valuated and adherence and display the total value in the input.
Membership = 3,500.33;
Dependants = 90.33;
Total Correct: 3,590.66
Code
<?php
$numerocontrato = trim($_GET["numerocontrato"]);
$sql =" SELECT sum(cast(replace(valordependente,',','.') as decimal(18,2))) as dep, replace(adesao,',','.') as ades";
$sql .= " FROM cadastro_clientes where numerocontrato = $numerocontrato ";
$consulta = $DB->query($sql);
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {
$soma1 = $linha['ades'];
$soma2 = $linha['dep'];
$resultadoSoma = $soma1 + $soma2;
echo "<input type='text' readonly value=" . number_format($resultadoSoma, 2, ',', ' ') . " placeholder='Total' id='total' class='form-control' name='total'><span class='error'></span>";
}
?>
I did not quite understand your doubt. The result is not going as expected?
– LocalHost
The result is normal, the problem is that I don’t know how to add these two values to the input. @Localhost
– Mauro Santos
What is displayed in the way this now?
– LocalHost
R$ 93,83 do not know why...
– Mauro Santos
I get it, I’m posting an answer now
– LocalHost