0
I’m having a problem with a search field on a php site with Mysql database.
I have a record in the bank as "SIPHON" and when I search as siphon, siphon or SIPAO does not return this record. I wish you wouldn’t differentiate between upper/lower case and special characters.
The table and records are already converted to latin1 and I am using this collation in the query, as you can see in the code below. It’s not even working.
Follows the code:
$texto = mysqli_real_escape_string($conn, $_POST['texto']);
$result = mysqli_query($conn, "SELECT DISTINCT
produtos.id as id,
produtos.nome as nome,
produtos.descricao as descricao,
produtos.tags as tags,
produtos.url as url,
ambientes.url as AmbienteUrl,
categorias.url as CategoriaUrl,
imagens.arquivo as ImagemArquivo
FROM produtos
INNER JOIN prod_amb ON prod_amb.produto_id = produtos.id
INNER JOIN ambientes ON ambientes.id = prod_amb.ambiente_id
INNER JOIN categorias ON categorias.id = produtos.categoria_id
INNER JOIN imagens ON imagens.produto_id = produtos.id
WHERE (produtos.nome LIKE '%".$texto."%' collate latin1_swedish_ci
OR produtos.descricao LIKE '%".$texto."%' collate latin1_swedish_ci
OR produtos.tags LIKE '%".$texto."%' collate latin1_swedish_ci)
AND produtos.situacao = 1
AND imagens.principal = 1
GROUP BY produtos.id");
while ($row = mysqli_fetch_assoc($result)) {
echo $row['nome'];
}
Please collaborate with the quality of community content by better elaborating your response. Very short answers will hardly be clear enough to add anything to the discussion. If your response is based on some function or feature of the language/tool, link to the official documentation or reliable material that supports your response. Searching for similar questions in the community can also be interesting to indicate other approaches to the problem.
– Woss