0

I'm using php and MySQL to display some result to a dynamic website. Now here's an array (generated depends on different input):

$myarr = array('aaa','bbb','ccc',...)

I want to test in MySQL if there's an existing value in table 'product_info' that is LIKE '%aaa%' or '%bbb%' or '%ccc%', just similar to what we do for IN keyword but with wildcards. If the value exists, I'll grab the row and display it, if not I'll do something else. No clue what the query statement in MySQL would look like.

Could anyone help with the statement?

Jasmin_W
  • 101
  • 6

1 Answers1

1

I would try regexp like this:

$array = array('aaa','bbb','ccc',...);

$string = implode('|',$array);

mysql_query("SELECT * from table where field REGEXP '".$string."'");
JTC
  • 3,344
  • 3
  • 28
  • 46