Sum of two tables and results display

1

I'm having problems in this section and I can not resolve "mysqli_fetch_array () expects parameter 1 to be mysqli_result",

$Valor = mysqli_query($conexao,"SELECT SUM(Y) AS TotalY AND SUM(X) AS TotalX FROM tabela");
while($rs = mysqli_fetch_array($Valor)){
$X = $rs['Y'];
$Y = $rs['Y'];
}

Would you have any means to subtract one from the other already within the first line?

    
asked by anonymous 29.06.2018 / 02:26

1 answer

0
$Valor = mysqli_query($conexao,"SELECT (SUM(Y) - SUM(X)) AS Resultado FROM tabela");
if($rs = mysqli_fetch_array($Valor)){
$X = $rs['Resultado'];
}

This solves your problem.

    
29.06.2018 / 18:41