The King is The King is - 3 months ago 10
PHP Question

Querying table foreach value in an array

I have an array which looks like this:

$array = array('1', '2', '3', '4', '5');


Now I also have database table column which its value is an imploded value. Now I want to
find_in_set
for each of the array value to see if its in the column also. For instance:

"SELECT * FROM table WHERE FIND_IN_SET('/*for each value in the array*/', column)"


So I can get the columns where each array value can be found.
Please how do I run this code

Answer

You can achieve that by first implode() your array like this

$implode_array = implode(',', $array);

Then you run your query like this

"SELECT * FROM table WHERE FIND_IN_SET(column, '". $implode_array."')"