Welcome Guest, Not a member yet? Register   Sign In
Trying to add parentheses im Active Record Query
#1

[eluser]edelcal[/eluser]
Hey guys. I was developing an SQL query and found out that i need parentheses for retrieving to correct data.
The query would look like this (i didnt show the joins):

SELECT * FROM (`media`)
WHERE `galleries`.`galleryShow` = 'y'
AND `galleries`.`galleryType` = 'video'
AND (`games`.`gameName_en` LIKE '%book%'
OR `games`.`gameName_es` LIKE '%book%'
OR `game_platform`.`keywords` LIKE '%book%' )
ORDER BY `mediaDate` desc

So i dont know how to enter a paretheses after the AND when i want to have some ORs between them, like in the example. With Active Records i can use: $this->db->or_like('games.gameName', '%book%' );
but i would like to be able to insert parentheses before and after all the OR querys.

Hope some of you guys have any idea for doing this.

Many thanks
#2

[eluser]Armchair Samurai[/eluser]
Something like:

Code:
$search = $this->db->escape_like_str('book');
$sql = <<<ENDSQL
(games.gameName_en LIKE '%$search%'
OR games.gameName_es LIKE '%$search%'
OR game_platform.keywords LIKE '%$search%')
ENDSQL;


$this->db->where('galleries.galleryShow', 'y');
$this->db->where('galleries.galleryType', 'video');
$this->db->where($sql, NULL, FALSE);




Theme © iAndrew 2016 - Forum software by © MyBB