0

here's my model code :

function total($id)
    {
        $this->db->select_sum('score');
        $q = $this->db->get('my_table');
        $this->db->where('id',$id);
        $this->db->group_by('id');
        return $q->row()->score;  

    }  

why the output still sum all of row not the specific row with id?

0

1 Answer 1

3

$this->db->get() actually runs the query. You need to call that last.

function total($id)
    {
        $this->db->select_sum('score');
        $this->db->where('id',$id);
        $this->db->group_by('id');

        $q = $this->db->get('my_table');
        return $q->row()->score;  

    }  
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.