3
I’m having a hard time changing a search that I have today by searching a code that has, for example this mask A 901.325.0744
the search is correct because the code is registered in this way and the search is now done without the point, trace and space, but how can I concatenate the LIKE
in my query making the search find the product by any term, I tried some alternatives and it did not work.
What I have is this, my initial SQL:
// PESQUISA INICIAL $sql = " SELECT produtos.codigo, produtos.nome, produtos.lancamento, produtos.id_categoria, produtos.id_produto, produtos.data_inicial, produtos.data_expiracao FROM `produtos` WHERE (produtos.id_idioma = '".$_SESSION['idioma']."') AND (produtos.`status` = 1) ";
To query
dynamics I created to concatenate the searches:
$sqla = " AND REPLACE(REPLACE(REPLACE(codigo_original,'.',''),'-',''),' ','') = REPLACE(REPLACE(REPLACE('".$pesquisa."','.',''),'-',''),' ','') OR
REPLACE(REPLACE(REPLACE(codigo_original1,'.',''),'-',''),' ','') = REPLACE(REPLACE(REPLACE('".$pesquisa."','.',''),'-',''),' ','') OR
REPLACE(REPLACE(REPLACE(codigo_original2,'.',''),'-',''),' ','') = REPLACE(REPLACE(REPLACE('".$pesquisa."','.',''),'-',''),' ','') OR
REPLACE(REPLACE(REPLACE(codigo_original3,'.',''),'-',''),' ','') = REPLACE(REPLACE(REPLACE('".$pesquisa."','.',''),'-',''),' ','')";
The search with the concatenated fields:
if ($sqla != "") { $sql = $sql . $sqla . $ordenacao; } else { $sql = $sql . $ordenacao; }
Some data from the table:
As an example, I would like the user to search 411
, term that is part of the original code column and original code_1 were displayed these records in the search result.,
Can provide examples of your data so we can provide a functional response?
– Sorack
Hi @Sorack What exactly you need?
– adventistapr
It puts about 3 lines with data from your table and the term you’re researching that would return one of them. So I can suggest substitutions or even an alternative way to solve your problem
– Sorack
In your example the other 2 records would not be shown?
– Sorack
Yes, they would be shown in the search result.
– adventistapr