Sum of two tables and display of results

Asked

Viewed 29 times

1

I’m having problems with this section and I can’t solve " 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 have some way to subtract one by the other already inside the first line?

  • Have you tried taking out the DNA and putting a comma?

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'];
}

That solves your problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.