mysql - Wildcard query in PHP renders in SQL not in PHP -
i've been fiddling query in php day or 2 now. i'm using php 5.4 mysql 5.6. query below works fine in sql, doesn't work in php. i've googled answer , searched stack overflow wildcard answers in php , sql. quite thorn in side @ moment why not working.
$search_string = preg_replace("/[^a-za-z0-9]/", " ", $_post['query']); $search_string = mysql_real_escape_string($search_string); $query = 'select * population location "'.$search_string.'%"';
let me know if need anymore information - i'm using phpmyadmin sql if helps.
thanks
edit: i'm trying wildcard search database of cities first 2 characters typed 'al' should produce autocomplete cities starting 'al'.
if include both wildcard in front %'.$search_string.'%"'; autocomplete expected (finding matching characters ever might in string), if remove first % returns "no results."
update:
$query = 'select * population location "%'.$search_string.'"';
returns city names starting last characters.
an example: typing 'al' returns "central, normal, etc." again if put wildcard in though php not parsing query.
so, curious , hard answer without more information have tried:
where lower(location) lower('".$string."%')
give me more information type of string might passed through query... believe may working additional wildcard due location being stored in proper case , string being lower or upper...
Comments
Post a Comment