I have a string array var and a DB table column containing comma-separated values (varchar) and I am trying to set up a query that would return all rows containing matching elements. See below:
// an array of random strings
$ItemsOfInterest=["item1", "item99", "item5"];
$imploded_items = implode("','", $ItemsOfInterest);
$query = "SELECT * FROM table_name WHERE `items` IN ('$imploded_items');
Let's say in the items
column of my table I have these five rows of sample data (VARCHAR):
(row1) item43,item60,item1
(row2) item1,item78
(row3) item24,item83,item5
(row4) item5
(row5) item71,item5,item93
The query above will only return a single row (the one containing only item5).
What I need is a query that will return all rows containing at least one of the comma separated values, which in the above example would be all five rows. Thanks.