gold spoon 1
gold spoon 2
rose gold spoon 1
rose gold spoon 2
rose gold spoon 3
I dont have color field inserted in database.
i want show “gold” and “rose gold” color products separately
if i write a query
$colors = array("gold","rose gold");
foreach($colors as $colr)
{
$q = "select product_name from products_table where product_name LIKE '%".$colr."%'"
}
then all results of “rose gold” are displayed under “gold” color results also.
There are 6 gold color products and 10 rose gold color products
First all 16 products are shown under “gold” color
then again 10 products are shown under “rose gold” color products
But i want to show 6 gold color products separately and 10 rose gold color separately.
not if the values are in an array - the only way to distinguish the two is by including both in the database call so as to say ‘gold’ and not ‘rose gold’ which means hard coding them in the query.
You can’t have array entries that are fully contained in other array entries to use with like as the shorter one will always include all the longer ones that contain it.
Without normalizing that structure filtering, and sorting against those product attributes is going to be a complex, inefficient process that does not scale well.
Than all you need to do is write a script to parse the existing products attributes into those tables,
You do that now you avoid a whole lot of issues and limitations in the future. One of which is your current problem turns into a simple join query rather than a convoluted string manipulation mess.