简体   繁体   English

将表数据存储到数据库中

[英]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. 上面的功能是由jQuery制作的,我的页面中有+按钮,用户可以添加带有子项的新主题,因此他可以有4个主要主题,每个主题可以拥有用户想要子主题的数量。

Now the question is, how I should store such details in db so it could be easy to edit and search? 现在的问题是,我应该如何在db中存储这些细节,以便编辑和搜索? currently I'm storing the table HTML data into db but it doesn't sound wise. 目前我将表格HTML数据存储到数据库中,但这听起来并不明智。

PS: 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. PS:当用户定义细节时,产品没有插入db YET ,因此我需要动态保存数据并在用户提交产品后插入它们。

Thanks for your help. 谢谢你的帮助。

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. 这将是一对多关系,其中每个表只有一个主题条目,但是根据需要有很多细节条目,然后在读取数据时,您只需通过subjectId上的连接加载两个表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM