Method to subtract two values from the sum of the records coming from the MySQL database

2

Good afternoon everyone, I'm creating a class that will work as a box

where it will add all the records found in the database with the column in the value of IN and OUT and in the end I subtract Input - Output but is not working anyone can tell me where I might be wrong?

Launch class function

public function getSaldo(){

    $conexao = new Conexao();

    $sql1 = "SELECT SUM(valor) FROM $this->table WHERE tipo = Entrada";
    $sql2 = "SELECT SUM(valor) FROM $this->table WHERE tipo = Saida";

    $entrada = $conexao->login($sql1);

    $saida = $conexao->login($sql2);

    $saldo = $entrada[0] - $saida[0];

    return $saldo;


}

Login function

public function login($rawQuery, $params = array()):array
{

    $stmt = $this->query($rawQuery, $params);

    return $stmt->fetchAll(PDO::FETCH_ASSOC);
}

Function testing page

<?php

require_once "../Controllers/Config.php";

$lancamento = new Lancamento;

$lancamento->getSaldo();


?>

The login class I am using temporarily want to implement a specific function for this case, since I thank you for any help

    
asked by anonymous 20.09.2018 / 22:01

0 answers