I'm trying to select products matching a customer's preferences (i.e. the colors they like), but I'm having trouble creating an IN statement when the value that's being assessed in the subquery is an array.
I'm only including a few fields in order to simplify the question, but there are a few hundred fields for each customer and about half of them are arrays, and there are apx. the same number of fields for each product.
This query doesn't work if more than one color has been selected:
$result = mysql_query("SELECT * FROM products WHERE color IN
(SELECT colors_love FROM style WHERE style.user_id=$user_id)")
I also tried exploding the array like this:
while ($row = mysql_fetch_array($result)) {
$colors_love = explode(',', $row['colors_love']);
echo $row['product_name']. ", ". $row['style']. ",". $row['color']. ", ". $row['price'];
}
Since that produced the same results, I'm assuming that's either not the issue, or that it needs be exploded before it is used in the query - which I'm not quite sure how to do.