0

Let's assume I have this array

$arr = array(1,2,3,4,5,6,7,8,9);

Then I also have a database table column which the value is imploded

column = '3,5,8,2,4';

Now I want to run a mysql query on each of the $arr value to see if it is in the column

I know FIND_IN_SET can go just for a string but I don't know if it's possible to do the FIND_IN_SET for an array.

  • 3
    The best solution isn't to use comma-separated data in a database column anyway, but to properly normalize your data – Mark Baker Jun 06 '17 at 16:17
  • You could use a query to select possible matches, and then before displaying that data as a match use php's `explode` on the column to make it into an array, and then use php's `in_array` to determine if its an actual match. – GrumpyCrouton Jun 06 '17 at 16:18
  • Are you retrieving column based on some other param? Ie you have the column extracted from sql and in a php variable? – nerdlyist Jun 06 '17 at 16:22
  • [1, 2, 3, banana, 5](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – Don't Panic Jun 06 '17 at 16:51

0 Answers0