There was a task to implement a mini online store. Feature - attributes of goods are dynamic, i.e. can be sold as a wing from Boeing, and shale. And the site should be made and given away, no technical support.
With such conditions, when building a database model, the EAV model was chosen as the most universal. Built a standard model, this is what it looks like:
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for attributevalue -- ---------------------------- DROP TABLE IF EXISTS `attributevalue`; CREATE TABLE `attributevalue` ( `attribute_id` bigint(20) NOT NULL, `product_id` int(11) unsigned DEFAULT NULL, `attribute_value` text, KEY `product_id` (`product_id`), CONSTRAINT `product_id` FOREIGN KEY (`product_id`) REFERENCES `productentity` (`product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Table structure for productattribute -- ---------------------------- DROP TABLE IF EXISTS `productattribute`; CREATE TABLE `productattribute` ( `attribute_id` bigint(20) NOT NULL, `product_id` int(11) unsigned DEFAULT NULL, `attribute_name` varchar(255) DEFAULT NULL, KEY `product_id_attr` (`product_id`), CONSTRAINT `product_id_attr` FOREIGN KEY (`product_id`) REFERENCES `productentity` (`product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Table structure for productentity -- ---------------------------- DROP TABLE IF EXISTS `productentity`; CREATE TABLE `productentity` ( `product_id` int(11) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`product_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4; But, in addition to the output attributes themselves, you need to implement a search for them.
For example, divide attributes into groups, and assign a filter type ( checkbox , range, drop-down list).
How to do it better? And you don't want to reinvent the wheel in the age of space flight ...