1
I have a simple search system that searches for values in the comic book and displays on the page. In the table I have a column called palavraschaves where the words I leave as a query parameter are registered. I need two things. The first is that when typing the word with uppercase or lowercase letter it understands the same way without I need to register both in the BD. The second thing is that it adds the words in the search. For example: I entered the words in the table in the following order; house building roof. If I type roof house does not return me anything, just search for one of the two. I want him to search for the two.
Code
$busca = trim($_POST['busca']);
$sql = mysqli_query($conn, "SELECT * FROM pesquisa_clientes WHERE palavraschaves LIKE '%".$busca."%' ORDER BY nome");
$numRegistros = mysqli_num_rows($sql);
if ($numRegistros != 0) {
echo "<h4 class='result'>Resultados para: <b> " . $busca . "</b></h4><br />";
while ($usuario = mysqli_fetch_object($sql)) {
echo "<div id='resultados'>";
echo "<img src='images/clientes/".$usuario->logo."' alt='Foto de exibição' /><br />";
echo utf8_encode("<h4><b> " . $usuario->nome . "</b></h4><br />");
echo utf8_encode("<p><span><b> " . $usuario->subcategoria . "</b></span></p><br /><br />");
echo utf8_encode("<p><b>Bairro:</b> " . $usuario->bairro . "</p><br />");
echo "<p><b>Telefone:</b> " . $usuario->telefone . "</p><br />";
echo "<a href='". $usuario->link_cliente. "'><b>Saiba Mais</b></a><br /><br />";
echo "</div>";
}
} else {
echo "<h4 class='result'>Nada foi encontrado com a palavra:<b> ".$busca."</b></h4>";
}
?>
I recommend limiting the question to a specific problem.
– Francisco
Could you show how the words are inserted in the database ? I don’t know if they are inserted separately, or the way the user type in the query. Show me this.
– Duque
I separated by simple space: home car plastic table
– Turkish
The first case has several subjects here: https://answall.com/questions/144251/como-trata-igualmente-strings-accentuas-sem-acento-num-like/144265#144265, https://answall.com/questions/192156/sql-like-%C3%A9-case-sensitivecaso-sensitive/192373#192373, https://answall.com/questions/72139/qual-encodes%C3%A7%C3%A3o-de-characters-collation-devo-usar-em-mysql/72142#72142.....
– Inkeliz
Turkish, choose a database/table meeting ending in _ci (meaning "case insensitive"), this will solve the case of upper or lower case letters. For the search problem, I recommend using mysql match Against. I already gave an answer once explaining the use of match Against, see this answer: https://answall.com/questions/187858/fazer-uma-busca-independente-da-ordem-das-palavras-chave/187895#187895
– Antonio Alexandre
Friends. I didn’t try the code you gave me because Leo’s solved my previous problem. But I changed the question because a new one came up.
– Turkish
I reversed the last edition because it changes the meaning, invalidating the existing answers so far.
– Daniel Omine
If you want to kill two rabbits in one shot, put the bench as utf8_general_ci. So you will not need to make as much effort for both cases, accentuation and high or low cash.. I stress that is not "the solution", but an option.
– Daniel Omine
Edited response to meet accent
– user60252