tags:

views:

67

answers:

1

I have two arrays of attributes that describe products in the database:

$sizes =   array(
                'Shirt Size' => array('Small', 'Medium', 'Large'),
                'Sleeve Size' => array('Short', 'Long')
                ); // Level 1
$colors =  array(
                'Shirt Color' => array('Black', 'Red'),
                'Sleeve Color' => array('White', 'Orange')
                ); // Level 2

The contents of those arrays above change frequently, and at some points "colors" or "sizes" may be empty.

What is the most efficient way to go about grouping these attributes, so I can see (for example) all Small & Short, Black & Orange products? I'm not as concerned with calculating the quantity of each attribute combination as I am with creating the attribute grouping mechanism.

I'd like to end up with a table like this:

SHIRT SIZE    SLEEVE SIZE    SHIRT COLOR    SLEEVE COLOR    QTY
Small         Short          Black          White           6
Small         Short          Black          Orange          1
Small         Short          Red            White           4
Small         Short          Red            Orange          2
Small         Long           Black          White           3
Small         Long           Black          Orange          2
...
Large         Long           Red            Orange          5
+1  A: 

Well, actual most efficient way is to not have all these "product attribute" in your application code, but to have them in the database as well.

Then, it would just be a question of joining your tables together in a query.

I'm curious, what does your data model look like now? How do you actually store the size/color/whatever information currently?

Peter Bailey
I have the following database tables: "Products," "Product Attributes," and "Product Attribute Options." Those attributes were pulled from the database into the array that is above.
James Skidmore
Yes, but how are you storing the relationship between a `Product` and its respective attributes
Peter Bailey