In PHP I have a function to return results for a search form.
function search($search) {
global $database;
$search2 = ( '%' . $search[0] . $search[1] . $search[2] . $search[3] . '%' );
$q1 = "SELECT * FROM location WHERE is_approved = 1
AND (city LIKE '$search'
OR state LIKE '$search'
OR state LIKE '$search2'
OR 'city' LIKE '$search2')";
$matches = $database ->query($q1);
return $matches;
}
The search2 variable is meant to wildcard search for four character matches in the location such as 'Cinc' matching 'Cincinnati'. To do this the query needs a wildcard with the % character before and after.
Whenever I run the query directly in MYSQL to test it, it works fine. Whenever I run this in the PHP code the wildcard portion doesn't seem to be working. If I echo %search2 as in my example, $search2 will echo %Cinc% which is what I presume it should be for a wildcard search. Why are no results returned for the wildcard portion?