0
I have a table like this:
And I need to add the value of id 1 to the value of id 15, saving to a variable in PHP.
I’ve researched a lot but I couldn’t get anything specific to it. Thanks for any help!
NOTE: I have been trying the following but is returning 1, when it is right to return 49.14:
$result = mysqli_query($conn, "SELECT SUM(valor) FROM tb_valores WHERE id = ($id1) OR id = ($id15) ");
echo $linhasemuso = mysqli_affected_rows($conn);
Unfortunately, it didn’t work here. I did so: $execute = mysqli_query($Conn, "SELECT * FROM tb_values WHERE id = '$id1' AND id = '$id15'"); $soma_total = 0; while($line = mysqli_fetch_array($execute)){ $sum = $line['value']; $soma_total = $sum + $soma_total; } echo $soma_total; And it still doesn’t work...
– Gustavo
A variable, in the id case, cannot be simultaneously equal to two distinct values. I believe you actually want to use the logical operator OR and not AND.
– anonimo
@anonimo It’s vdd, I was wrong about that part
– Geraldão de Rívia