I have tables similar to these here. ( these are rough examples).
// List of products
product
id: int,
hash: varchar(255),
created: datetime,
modified: timestamp
// List of available product attributes
product_attributes
id: int
attribName: varchar(255),
created: datetime,
modified: timestamp
// Map of attributes available for a product
product_attribute_map:
id: int,
productId: int (FK product.id),
productAttributeId: int (FK product_attributes.id),
created: datetime,
modified: timestamp
// Values assigned to the attributes.
product_attribute_values
id: int
productId: int (FK product.id),
productAttributeId: int (FK product_attributes.id),
productAttributeValue: varchar(255)
created: datetime,
modified: timestamp
I want to be able to select all the products and their attributes and values. I would like the product_attributes.attribName to be the name of the column, and the product_attributes_values.productAttributeValue to fall into place under them in the query. I need this to be done dynamically I am not sure how to do it though.
Thoughts? Can this be done dynamically? or am I daydreaming?