Return Select Value

0

Hello, I would like to know how to retrieve a result from a select in Controller to perform a sum of variables. I have two selects that need the value resulting from them to add up inside the Controller.

    // A = select total ja proposto
    $this->db->select('SUM(tb_proposicao.valor) as totalproposto');
    $this->db->where('tb_proposicao.usuarioid', 1;
    $this->db->where('tb_proposicao.tipoid', 1;
    $dados['totalproposto'] = $this->db->get('tb_proposicao')->result();


    // B = select limite
    $this->db->select('*');
    $this->db->where('tb_limites.usuarioid', 1;
    $this->db->where('tb_limites.tipoid', 1;
    $dados['limites'] = = $this->db->get('tb_limites')->result(); 

    $A + $B = $C
    
asked by anonymous 02.04.2018 / 00:38

1 answer

0

$A = $this->db ->select('SUM(tb_proposicao.valor) as totalproposto') ->where('tb_proposicao.usuarioid', 1) ->where('tb_proposicao.tipoid', 1) ->get('tb_proposicao')->row(); Row (), will only give me an object column

For calculations to "B" will return the entire table, kick that will be a count.

$B = $this->db ->select('count(*) as limite') ->where('tb_limites.usuarioid', 1) ->where('tb_limites.tipoid', 1) ->get('tb_limites')->row();

Having both objects suffice adds values It is interesting to inform the data types returned, whether float, double, int .. for calculations.

$C = floatval($A->totalproposto) + intval($B->limite);

    
06.04.2018 / 01:01