I have a color array and want to match the color row in MYSQL,
as long as the color row match one of the colors in array, then take it out.
the following $colorArray
should match id 2 & 3, because those rows contain yellow & blue
$colorArray = array('yellow','blue');
+------+---------+------------+
| id | product | color |
+------+---------+------------+
| 1 | tShirt | red,green |
| 2 | jeans | yellow,red |
| 3 | shorts | black,blue |
+------+---------+------------+
I just want a MySQL SELECT syntax, I know it can be done with PHP array_intersect
to do some filters, but I don't want to for some reasons.
So is it possible?
$sql
part from$sql = "DELETE FROM <your_table_name> WHERE REGEXP '".$colorsStr."'";
to$sql = "SELECT * FROM <your_table_name> WHERE REGEXP '".$colorsStr."'";