Such situation:
1) There is a SELECT * FROM table WHERE name LIKE '%'.$search.'%'
2) Suppose there is a phrase Advanced O , then it will print all the lines with the entry of this phrase
3) How to make the word / character separated by a space separated, i.e. with the phrase Advenced O not only the string Advenced Other , but also Advenced Error

It turns out it is necessary to display the lines with the entry of the word Advenced and the letter "O"

    3 answers 3

    Replace spaces in the variable with the % wildcard. For example:

     SELECT * FROM table WHERE name LIKE '%' + replace(.$search.,' ','%') + '%' 

    But in this case there are no lines in the results, where the letter O comes before the word Advanced . That is, a string like Other Advanced will not be included in the selection.

    • Thank you, how can you make it so that you can still make a sample up to regardless of the position of keywords (As you wrote "Other Advanced")? - Samar
    • name like% Advanced% [or / and] name like% O% - IvanZakirov

    how can you make it so that you can still make a sample up to regardless of the position of the keywords

    For example:

     // Разбиваем исходную строку на фрагменты: $words = explode(' ', $string); // или preg_split() // Теперь получаем все перестановки слов, то есть: // $permutations[0] = [ "O", "Advanced" ] // $permutations[1] = [ "Advanced", "O" ] // Как? Вопрос ОЧЕНЬ часто задаваемый, гуглится без проблем. // Да и для тренировки можно самому подумать :) $permutations = get_permutations( $words ); // Формируем строки для LIKE: $likes = array(); foreach( $permutations as $permutation ) { // $likes[] = "%O%Advanced%" и т.д. $likes[] = '%'.join( '%', $permutation ).'%'; } // Ну и в самом простом случае: $where = '`name` LIKE "'.join( '" OR `name` LIKE "', $likes ).'"'; // $where = `name` LIKE "%O%Advanced%" OR `name` LIKE "%Advanced%O%" 

      Apply a function of type replace to $ search, and replace the spaces with%.

      Late. :-)