Complicated "like" queries |
[eluser]MaartenDeGroote[/eluser]
Hi everyone, Is it possible in CI to perform a query like the one stated below using $this->db->like(args)? Code: SELECT * FROM table WHERE column1 LIKE '%arg1' AND (column2 LIKE '%arg2' OR column3 LIKE '%arg2') Thanks in advance! Regards, Maarten
[eluser]bretticus[/eluser]
If you don't need parens in your second set of like clauses: checkout Code: $this->db->or_like() Sometimes AR is not the answer for everything. In fact, it's meant to simplify your database querying. When it begins to complicate it, it's time to use a real query IMHO. Cheers!
[eluser]danmontgomery[/eluser]
Code: $this->db->like('column1','arg1','before')->where('(column2 LIKE "%arg2" OR column3 LIKE "%arg2")', NULL, FALSE)->get('table') Code: $this->db->query("SELECT * FROM table WHERE column1 LIKE '%arg1' AND (column2 LIKE '%arg2' OR column3 LIKE '%arg2')");
[eluser]bretticus[/eluser]
Ah, simple genius @noctrum. Just roll a where clause in there with parens, etc. That certainly simplifies things. If you want to use AR, use that @MaartenDeGroote.
|
Welcome Guest, Not a member yet? Register Sign In |