Searching words in two column

suyilmaz

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?

`

Gorkem Yontem

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python searching for two words regex

From Dev

Grep searching two words in a line

From Java

Searching for and printing two key words in set

From Dev

Searching an excel with two search words (multiple lookup) using vba macro

From Dev

postgresql select like one column two words

From Dev

Searching individual words in a string

From Dev

Searching for words in Outlook 2010

From Dev

Searching 2 words in php

From Dev

filter words for searching in mysql

From Dev

Searching for partial words on Safari

From Dev

Ansible task for searching words

From Dev

Regex only searching for words

From Dev

Excel - Return list of row results based off searching a keyword in a column with multiple words

From Dev

EF filtering/searching with multiple words

From Dev

Mysql, PHP, searching for multiple words

From Dev

Solr not searching for words ending in "e"

From Dev

Searching multiple patterns (words) with ack?

From Dev

Trouble searching a string for words python

From Dev

EF filtering/searching with multiple words

From Dev

Segregating title into words and searching in a title

From Dev

How to get two words from one column in MYSQL

From Dev

Searching for two matches in perl

From Dev

Searching items in two lists

From Dev

Searching a matrix by row and column

From Dev

SSMS Searching for a Column

From Dev

Does creating an index on two columns x and y makes queries faster when searching on column x only?

From Dev

Searching two column titles, comparing, and deleting duplicate rows from one sheet only.

From Dev

Searching a twitter list for certain tags or words

From Dev

PostgreSQL Fuzzy Searching multiple words with Levenshtein

Related Related

HotTag

Archive