Welcome Guest, Not a member yet? Register   Sign In
Looking for simple way to Not escape active record db->like() search string
#1

[eluser]Monarobase[/eluser]
Hello,

I'm building a search form and want users to be able to search for more than one words...
(The product names could be new-product-name or new product-name or new, pruduct ! name)
Using preg_replace I remove all bad characters and replace the with a wildcard to get something like this :

Code:
$searchfor = 'new%product%name';

I wanted to look for it using :

Code:
if($searchstring != '') $this->db->like('prodname', $searchfor, 'both');

But the wildcard characters are escaped and no products are returned. I was thinking about expanding the active record library but I have noticed that it's in the database folder and not in the library folder. How would I go about doing this ? should I create a MY_DB_active_rec.php in my appications library folder ? Or could you recommend another approach to get the right search results ?

Thanks.
#2

[eluser]danmontgomery[/eluser]
Use where and pass FALSE as the 3rd parameter to prevent automatic escaping

Code:
$this->db->where('`prodname` LIKE "%new%product%name%"', NULL, FALSE);
#3

[eluser]Monarobase[/eluser]
Thankyou that solved my problem.




Theme © iAndrew 2016 - Forum software by © MyBB