Tauras Tauras - 3 months ago 9
Ajax Question

Search query does not work as expected using multiple LIKE condition

Search query shows zero results, if using gap between words. For example:

DB:

TABLE NAME - peoples
-----------------------------------
ID - forename - surname
-----------------------------------
1 Johny Depp
2 Kobe Bryant
3 Random Name
4 Mark Zuckerberg

etc


Query:

$sqlnames="SELECT id, forename, surname FROM peoples WHERE forename LIKE '%$search_keyword%' OR surname LIKE '%$search_keyword%' LIMIT 20";


If, for example in the input i am typing: Johny it shows as expected: John Depp, or if i am typing surname: Depp, it also shows as expected, but if i am typing full name: Johny Depp, it gives zero results. How i can fix that?

Sorry for bad english, and thanks for any answers!

Answer

Here is your query.

$sqlnames="SELECT id, forename, surname FROM peoples WHERE forename LIKE '%$search_keyword%' OR surname LIKE '%$search_keyword%' OR 
CONCAT(forename, ' ', surname ) LIKE '%$search_keyword%'
 LIMIT 20";
Comments