Adding values of 1 Mysql Column with codeigniter

Asked

Viewed 132 times

1

I need help fast. I am trying to create a function in Models, where only add the values of the 'value' column of a table. I’ve researched several questions here and I’ve asked them, but they’re not working. The code is this:

    function sumContasPagar() {
    $this->db->select('lancamentos.*');
    $this->db->from('lancamentos');
    $somaCP = "SELECT SUM(CASE WHEN baixado = 0 AND tipo = 'despesa' THEN valor END) as SOMACP FROM lancamentos";
    $resultado = mysql_query($somaCP);

    return $this->db->get()->result();

}

If this function is correct, then I am unable to call in the View. The view code is below:

echo 'Valor Total R$: '.$cr->valor;

And in Controller it’s like this:

$this->data['somaPagar'] = $this->mapos_model->sumContasPagar();

Someone help me, and preferably not deny me. I’m sorry if I’m not able to ask objective questions, because I’m starting in PHP and I don’t have much information.

  • I don’t know in your php, but in mysql you can change to SELECT SUM( value) as SOMACP FROM downloaded Where releases = 0 AND type = 'expense' see if it solves.

  • Okay buddy... I’ll try.

  • GOKU SSJ4, did not fail, which made me very happy. But how do I call this result in Views? I’m putting this: echo 'Total Value R$: '.$cp->summePagar;

  • where this "sum" is being called in the controller. But it gives this error: PHP Error was encountered Severity: Notice Message: Trying to get Property of non-object Filename: mapos/dashboard.php Line Number: 104

  • No manjo de php

  • ok friend... thanks for your help. vlw!

  • @Jardeldint you duplicated the questioning, delete that if you can!

  • as well, I did not understand?

  • You asked two equal questions here, because, let her both that could be excluded! Spam understood.? solutions are similar in fact changes the method only

Show 4 more comments
No answers

Browser other questions tagged

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