1

What I want to do is use sum if in codeigniter, it's got error when I run in browser, but I query in MYSQL, there are not error and working nicely.

Here is my code

$this->db->select('sum(if(`monitoring_type` = 1,1,0)) AS independent,sum(if(`monitoring_type` = 2,1,0)) AS buddy,count(*) AS TM, rate_info.qm_title');
$this->db->from('qm.recordings');
$this->db->join('qm.rate_info', 'recordings.record_id = rate_info.record_id');
$query = $this->db->get();
return $query->result();

my Error enter image description here

MYSQL

enter image description here

1 Answer 1

5

Add FALSE as the second parameter to

$this->db->select('your Query', FALSE);

Update:

It removes the escape identifiers (the backticks) from the select statement which codeigniter does by default for each query. So

SELECT `column1`, `column2` FROM table

will become

SELECT column1, column2 FROM table
Sign up to request clarification or add additional context in comments.

1 Comment

@Prabhukiran can you explain me why FALSE is required?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.