Database andlike() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Database andlike() (/showthread.php?tid=6561) |
Database andlike() - El Forum - 03-04-2008 [eluser]Hyra[/eluser] Hey hey, Im building a query which does a few joins and has a couple of where's. Works fine. Now I want to add "search" functionality so am playing with the $this->db->like and orlike But I want to search on at least 2 fields, and "orlike" will then break the query as it's standalone, making the previous where's obsolete. The query produced (simplified): Code: SELECT What i actually want is the where's to be encapsulated by ( )'s, so it would be like: Code: AND ( TableA.Title LIKE '%search%' OR TableB.Description LIKE '%search%' ) Anyone know how to achieve this? I'm using method chaining, so every method adds another where, and the final method should add the like's Code: function getBySearch($search = "") { Database andlike() - El Forum - 03-04-2008 [eluser]Armchair Samurai[/eluser] You'll have to do something like this: Code: $search = $this->db->escape("%$search%"); Database andlike() - El Forum - 03-04-2008 [eluser]Hyra[/eluser] Ah! Didn't know you could just put a full condition into the where() param Niceness, works like a charm. Cheers |