Welcome Guest, Not a member yet? Register   Sign In
Complicated "like" queries
#1

[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
#2

[eluser]bretticus[/eluser]
If you don't need parens in your second set of like clauses:

checkout
Code:
$this->db->or_like()
in the manual.

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. Smile

Cheers!
#3

[eluser]danmontgomery[/eluser]
Code:
$this->db->like('column1','arg1','before')->where('(column2 LIKE "%arg2" OR column3 LIKE "%arg2")', NULL, FALSE)->get('table')
or
Code:
$this->db->query("SELECT * FROM table WHERE column1 LIKE '%arg1' AND (column2 LIKE '%arg2' OR column3 LIKE '%arg2')");
#4

[eluser]bretticus[/eluser]
Ah, simple genius @noctrum. Just roll a where clause in there with parens, etc. That certainly simplifies things. Smile If you want to use AR, use that @MaartenDeGroote. Smile
#5

[eluser]MaartenDeGroote[/eluser]
Cool! Thanx!




Theme © iAndrew 2016 - Forum software by © MyBB