I have a SQL that returns me the following:
1: Hacker And Cars
OU
2: Food
I need to get it back:
1: Hacker
E
2: Automotive OR Food
The code I have so far is:
if(!$final['termo'] == null) {
$this->db->like('bl_title', $final['termo']);
}
if(!$final['categorias'] == null) {
$c = 0;
foreach($final['categorias'] as $cats){
$c++;
if($c == 1){
$this->db->where('bc_urllink', $cats);
} else {
$this->db->or_where('bc_urllink', $cats);
}
}
}
There is a missing parenthesis in the where/or_where
condition of bc_urllink that I do not know how to put.
In pure SQL, it looks like this:
$result = $this->db->query("
SELECT * FROM blogs AS bl
INNER JOIN blog_categoria AS blc
ON bl.bc_id = blc.id
WHERE bl.bl_title
LIKE '%Hackers%'
AND (blc.bc_urllink = 'automoveis'
OR blc.bc_urllink = 'alimentacao')
");
Thanks for the help.