Results 1 to 3 of 3
Jul 13, 2011, 18:52 #1
Escaping wildcard characters like % in mysql "LIKE" statement.
Can anyone explain, how i can escape wildcard chars like % in the mysql like statement.
For example consider the below query
$keyword = '100';
$query = "SELECT * FROM `someTable` WHERE `keyword` LIKE '%".$keyword."%' ";
In the above case it will work fine and will list all records matching 100. Now i want to list all records matching the keyword '100%'. I want 100% to matches one-hundred-percent and not just any string starting with a hundred. How will i do this. I have tried to escape it using addslashes/mysql_real_escape. Both will not escape %.
Can anyone suggest a solution with an example.
Jul 13, 2011, 21:02 #2
- Join Date
- Jul 2008
- 0 Post(s)
- 0 Thread(s)
Backslash ' \ ' should work.
$query = "SELECT * FROM `someTable` WHERE `keyword` LIKE '%".$keyword."\%' ";
Jul 14, 2011, 02:09 #3