'using a column name in an array within a query
Right, I have a question to do with a MySQL query.
What I'm trying to do is query my database, and get a result where the category_name equals one of my array keys, and the subcategory_name equals one of the array key's values.
$this->bar['images'] = ["body" => ["soap", "wash", ], "deodorant" => ["spray", ], "eye" => ["cream", ], "face" => ["masks", "moisturiser", "wash", ], "grooming" => ["trimmers", ], "hair" => ["shampoo", "wax", ], "lip" => ["balm", ], "shaving" => ["cream", "foam", "gel", ], ];
So, for example, return a row where category_name equals shaving and subcategory_name equals foam.
Using whereIn I can easily link the array key to the category_name column, however... it's the subcategory_name I'm struggling with.
$array = $model->whereIn('category_name', array_keys($bar['images']))->whereIn('subcategory_name', array_values($bar['images'][CATEGORY_NAME]))->groupBy('CONCAT(subcategory_name, category_name)')->orderBy('RAND()')->findAll(3);
If I could find a way to use the category_name within a second whereIn clause by tacking it onto the end of the array array_values($bar['images'][CATEGORY_NAME]), I'd be fine - but I'm struggling with syntax and tried several ways to use wildcards etc.
Any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
