Hello. I have a task to find parts of the text in certain matches, but unfortunately the function works if a whole text is found.
Example: we are looking for an АБВ cell, the cell contains 123, АБВ, 456 - zero reaction, if it finds an АБВ cell, then it finds everything.

The code is as follows:

 $result=mysql_query('SELECT virtuemart_product_id FROM virtuemart_products WHERE "Стена" in(product_parametr1, product_parametr2, product_parametr3)'); 

Thank you in advance

  • It is possible that tools such as Elasticsearch, Sphinx, etc. for your current level they will be difficult ( although it's better to get used to “good” right away ), but you can look towards full-text search - Deonis

2 answers 2

Try

 SELECT virtuemart_product_id FROM virtuemart_products WHERE product_parametr1 LIKE "%Стена%" OR product_parametr2 LIKE "%Стена%" OR product_parametr3 LIKE "%Стена%" 

    We are looking for an ABC cell, the cell contains 123, ABC, 456 is a zero reaction, if it finds an ABC cell, then it finds everything.

    In such cases, it is necessary not to compare, namely what to check for occurrence. Possible test options:

     WHERE field LIKE '%АБВ%' WHERE INSTR(field, 'АБВ') 

    Code next

    There is a suspicion that one of the three fields to be checked is exactly equal to the required literal. Then:

     WHERE "Стена" = product_parametr1 OR "Стена" = product_parametr2 OR "Стена" = product_parametr3 

    But if we are looking for the entry of a literal as a substring in one of the three fields, I would recommend using:

     WHERE INSTR(CONCAT(product_parametr1, product_parametr2, product_parametr3), 'АБВ') 

    All the same, the field indices will not be used, and so concatenation and one search will be performed (even if on a longer string), rather than three separate searches, IMHO so it will be a bit faster.

    • Thank you, this method went perfectly. And how can you now make two different matches compared? like so: SELECT virtuemart_product_id FROM ak89e_virtuemart_products WHERE INSTR ( CONCAT (product_parametr1, product_parametr2), " The Wall" AND INSTR (CONCAT (product_parametr1, product_parametr2), " Paul," I need to get the id is of the goods, in which there are multiple matches Thank you in advance. - Riad
    • already done, thanks) - Riad
    • there was a passing question. How can I insert a request body into a query that is specified in a variable? for example: $ spisok = 'product_parametr1, product_parametr2, product_parametr3, product_parametr4, product_parametr5'; $ result = mysql_query ('SELECT virtuemart_product_id FROM ak89e_virtuemart_products WHERE INSTR (CONCAT (". $ spisok.'") - Riad
    • also did) the problem was in the incorrect closing of the bracket - Riad