Search query:
"product1 prod2 prod4"
I need to do mysql
SELECT * FROM tableprod WHERE (prod LIKE '%product1%' AND prod LIKE '%prod2%' AND prod LIKE '%prod4%')
using mysql_real_escape_string for input request ...
Simple string manipulation:
$terms = explode(' ', $search); $bits = array(); foreach ($terms as $term) { $bits[] = "prod LIKE '%".mysql_real_escape_string($term)."%'"; } $query = "SELECT * FROM tableprod WHERE (".implode(' AND ', $bits).")";
If you cope with the restrictions, it would be better for you to use the FULLTEXT index , which saves you from having to split the string, plus you get a bonus to be able to use basic logical operators for searching (and / or / not)
( ):
$str = "product1 prod2 prod4"; $sql = "select * from tableprod where (prod like '%" . str_replace( ' ', '%\' AND prod LIKE \'%', $str ) . '%\')';
, , preg_replace
Source: https://habr.com/ru/post/1768906/More articles:JComboBox causes a runtime error - javaforum comments on a web page - asp.netQuestion about data template or style in WPF xaml - data-bindingLinux: modeling packet reordering - linuxHow to get a list of ports that are used on a server from Delphi - command-lineWorkaround for adding ActionListener to JTextArea - javaОшибка приложения в NSURLConnection - iosSinatra shotgun problem - undefined methoddefault - ruby | fooobar.comHow to compile and link using gnatmake with the Ada shared library? - adagetElementById does not work with node - javascriptAll Articles