0

In product detail page, I want to display a table of specifications with two column and many rows. I could do it easily by storing the specs in JSON file, but I guess it will not be the best way as all data should be stored in the database. As I have like 100 products already put in a table of products in database, so if I want to store specs table it means that I will have to create 100 more table, each table is for one products in the database. I thought it would not be the best solutions, so how can I solve this problem. Please notice that each specs table will have different number of rows and information. My JSON object containing product_specs is like below:

      "111": {

        "product_specs": [
            {"header":"Brand", "data": "Dell"}, 
            {"header":"Model", "data": "XPS"},
            {"header":"Origin", "data": "USA"},
            {"header":"Production year", "data": "2022"}
        ]
    },
    "119": {
        "product_specs": [
            {"header":"Manufacturer", "data": "Acer"}, 
            {"header":"Series", "data": "A"},
            {"header":"Purpose", "data": "Learning"},
            {"header":"Warranty", "data": "2 years"},
            {"header":"Gifts", "data": "X watch"}
        ]
    }

My desired table in detail page: enter image description here

Research for hours, still stuck.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
  • As I know, it's only possible to store string, not array in table cell, so I think it would be difficult processing such string to put in multiple table rows in html table – Tập Cận Bình May 16 '23 at 11:18
  • 1
    Short answer, it depends. Long [answer](https://stackoverflow.com/questions/2945045/database-design-products-attributes-what-is-better-option-for-product-attri). In relational database its better to create a table specifically for product properties, because some products share some of them or all of them. In none relational way you can store everything in one single `document`. The problem is, that most of the NoSQL solutions cannot `join` and you will need to make it manually in the code. Also it depends on amount of SKUs in table and how efficient will be the solution. Your call. – Sergey Ligus May 16 '23 at 11:21
  • I'm reading about relational database and it's great, takes time to build but easier for scaling and managing. Thanks. – Tập Cận Bình May 16 '23 at 11:56
  • If you want to store the specifications of a product, make a table called product_specs with an autonumber id, a foreign key that is product_id, and all the other fields you need for the specs. So for each product you will have a record of its specifications. If they have different specifications, you can make the table so that each row of the table is a specification of a product. (id, product_id, specification) – Julian Fagadau May 16 '23 at 13:10
  • I'm experimenting it now, thanks – Tập Cận Bình May 16 '23 at 13:17

0 Answers0