I have an address field and address is stored similar to 1111 address info, county
$stmt = $db->prepare('SELECT * FROM ' . Config::USER_TABLE . ' WHERE ' . Config::SEARCH_COLUMN . ' LIKE :query ORDER BY '.Config::SEARCH_COLUMN.' LIMIT ' . $start . ', ' . $items_per_page);
$search_query = $query.'%';
$stmt->bindParam(':query', $search_query, PDO::PARAM_STR);
At the moment I can only search the field by it is number. I want to be able to type any letter and be able to search. Any ideas??? Thanks
The %
sign you attach to your parameter acts as an SQL wildcard:
$search_query = $query.'%';
Since you only attach it to the end of your parameter, it will only search for the string in the beginning of the column values.
Instead, also add one in the beginning of your parameter:
$search_query = '%'.$query.'%';
This way, it will look for the string in any position.