0

I have a custom query like this

SELECT `wo_number`,`request_date`,`wo_type`,`requestor` 
FROM `work_orders` 
WHERE CONCAT(",", `assigned_to_enggs`, ",") REGEXP ",(21),"

It works fine for me I want to use it in Codeigniter Active Record. I have tried something like

$this->db->select('wo_number,request_date,wo_type,requestor')
->from('work_orders')
->where("CONCAT(',', assigned_to_enggs, ',') REGEXP ',(21),'");

Don't know what I am doing wrong in syntax. can someone guide me. Thanks

2
  • I ran your active record script and printed out the compiled query with CI3 and got: SELECT `wo_number`, `request_date`, `wo_type`, `requestor` FROM `work_orders` WHERE CONCAT(',', assigned_to_enggs, ',') REGEXP ',(21),' How is your built query rendered? We don't know. Are you using the correct db driver to suit your database dialect? Notice the difference between your raw query with double-quoted values versus the where() method where you have hardcoded single-quotes around values. Commented Jun 3 at 5:15
  • 1
    See this answer for fully dynamic (driver-dictated) quoting around values and entities. Commented Jun 3 at 5:17

1 Answer 1

2

Please try below case in where and use result() for get result array

$this->db->select('wo_number,request_date,wo_type,requestor');
$this->db->where("CONCAT(',', assigned_to_enggs, ',') REGEXP ',(21),'", NULL, FALSE);
$this->db->select->from('work_orders');    
$query = $this->db->get()->result();

If not work than you also write query like below in codeigniter.

$query = $this->db->query('YOUR QUERY HERE');
$query->result()
Sign up to request clarification or add additional context in comments.

1 Comment

thanks it worked.. BTW find_in_set() method is another way of doing it ->where("find_in_set($get_engineer_id, wo.assigned_to_enggs)");

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.