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.
– Marco Souza
Okay buddy... I’ll try.
– Jardel Dint
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;
– Jardel Dint
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
– Jardel Dint
No manjo de php
– Marco Souza
ok friend... thanks for your help. vlw!
– Jardel Dint
@Jardeldint you duplicated the questioning, delete that if you can!
– novic
as well, I did not understand?
– Jardel Dint
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
– novic