I am using this autocomplete tutorial to perform an autocomplete search. The problem is in SQL it displays autocomplete for more than one word only if the words are in sequence.
Example: The quick brown fox jumped over the lazy dog.
If the search is performed for quick, it will display all results containing quick. But if I perform a search for quick lazy, it doesn’t display anything. On the other hand, if I perform a search for quick brown, it will display the above sentence.
How can I make the search autocomplete for more than one word in any random order?
This is the SQL:
$sRequest = "SELECT * FROM `table` WHERE `columnname` LIKE '%{$sParam}%' ORDER BY `columnname`";
$aItemInfo = $GLOBALS['MySQL']->getAll($sRequest);
foreach ($aItemInfo as $aValues) {
echo $aValues['columnname'] . "\n";
}
You should split your array of words to search and build a query like this: