Welcome Guest, Not a member yet? Register   Sign In
where() and like() are not working together
#1

[eluser]Nartub[/eluser]
Hello.

I'm trying to make a query which goes:

Code:
$this->db->where('column1','match1');
$this->db->like('column2','match2');

and when I get() it, the where clause is not working.

Could it be because the like() is adding another WHERE?

Thanks in advance.
#2

[eluser]CroNiX[/eluser]
Try changing the order. Sometimes it matters.
#3

[eluser]Nartub[/eluser]
Ahh I've found the problem. Thing is like this:

Code:
$this->db->where('column1', 'match1');

$this->db->like('column2', 'match2');
$this->db->or_like('column3', 'match2');
$this->db->or_like('column4', 'match2');

So the query is:

Code:
...WHERE column1 = match1 AND column2 LIKE match2 OR column3 LIKE match2 OR column4 LIKE match2

But it should be:

Code:
...WHERE column1 = match1 AND (column2 LIKE match2 OR column3 LIKE match2 OR column4 LIKE match2)

Is there any way to do this?

Thanks!
#4

[eluser]CroNiX[/eluser]
Not in this version. There is in the next version with grouping that you can download on github.
#5

[eluser]Nartub[/eluser]
Awesome, thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB