Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing table data into database

I am designing a web app which the users could post their products into it, each product will have a section as "Technical Specifications".

This is like:

Subject 1
Title 1: Description 1
Title 2: Description 2
Title 3: Description 3

Subject 2
Title 1: Description 1

So for example TV could get something like:

Main Details
Size: 18 inches
Color: Black
Style: Wide
HD: Yes

Supplementary Details
Guarantee: Yes
Support: No

The above functionality has been made by jQuery, there are + buttons in my page, the user could add new Subject with sub items, so he could have 4 main Subject, each of them could have as many as the user wants sub details.

Now the question is, how I should store such details in db so it could be easy to edit and search? currently I'm storing the table HTML data into db but it doesn't sound wise.

P.S: While the user is defining the details, the product is not inserted to db YET, so I need to keep data on the fly and insert them after the user submitted the product.

Thanks for your help.

like image 273
behz4d Avatar asked Jul 14 '26 09:07

behz4d


1 Answers

If I'm understanding you correctly you'd need two tables for this.

Subject table
 - subjectId
 - subjectName

Details table
 - detailsId
 - detailsName
 - detailsNote
 - subjectId

This would be a one to many relation where you would have only one subject entry per table but as many details entries as necessary, then when reading the data back you'd just load both tables via a join on the subjectId.

like image 137
Rick Calder Avatar answered Jul 17 '26 14:07

Rick Calder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!