i am working on a search script and this is
my php code:
$search_string = preg_replace("/[^A-Za-z0-9çğıöüş]/", " ", $_POST['query']);
$search_param = '%'.$search_string.'%';
// Do Search
$result_array = search_by_name($search_param); //functions
and i have a query like this:
SELECT user_id AS id,
user_firstname AS firstname,
user_lastname AS lastname,
user_profile_picture AS picture
FROM users WHERE
user_firstname LIKE :user_firstname
OR user_lastname LIKE :user_lastname
$result->bindParam(':user_firstname', $search_param, PDO::PARAM_STR);
$result->bindParam(':user_lastname', $search_param, PDO::PARAM_STR);
when you write a word, this query finds it in user_firstname column or in user_lastname columns. For instance,
`user_firstname user_lastname
-------------- -------------
james wood
jimmy james
george wood
in this case if I write 'james' to the search area, I'll find 'james wood' and 'jimmy james' however, if I write 'james wood' I won't find anything because i am searching it in user_firstname column or user_lastname colum which does not contain 'james wood'.
what I want to do is to be able to search full names and get the results. how do I do this?
`
Create an new column something like user_first_last_name. put the first names and last names together. And search from that column.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments