Skip to content
Advertisement

Query with a PHP foreach using OR and LIKE %?

I have sort of a tricky problem, and I want to see if there is an easier way about solving it.

I have let’s say

JavaScript
  • The count in the array may vary depending on the $_GET value…
  • These need to search using ‘%” . $number. “%’ because there might be more than one number in the row separated by commas

My ideal result would perform a search for the $numbers(1,2,3) with:

JavaScript

Advertisement

Answer

No need to inject many OR operators for each element of the Array. Instead you can use rlike (the regex matcher operator of MySQL) and simplify your code to a great extent like this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement