The King is The King is - 1 year ago 110
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
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 Source

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."')"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download