How can I achieve name matching. Something like "John S Smith" must match "Smith John S" in mysql database. i.e words can be unordered.
Is it possible to do this in a single SQL query? Since it is for names it will not exceed 3 words.
My code is not logically correct. Any help would be highly appreciated.
$words=explode(" ", $name);
$sql="SELECT * FROM sent WHERE 1=1";
foreach ($words as $word)
{
$sql.=" AND customer_name LIKE '%$word%'";
}
The Resulting SQL that I have looks like this.
$sql="SELECT * FROM sent WHERE 1=1 AND customer_name LIKE '%John%' AND customer_name LIKE '%S%' AND customer_name LIKE '%Smith%'" ;