MYSQL数据库中如何在一个字段中存储多个字段

发布于 2024-11-14 15:48:57 字数 327 浏览 2 评论 0原文

如果这是一个愚蠢的问题,我很抱歉,但我对此很陌生。我想将所有客户的不同联系表单中的所有信息存储在数据库中,以便他们以后可以检索信息。每个联系表单都有不同数量的字段。理想情况下,我会将所有这些信息存储在一个 MYSQL 表中,但正如我所说,每个客户的联系表单都有不同数量的字段。

我正在考虑创建一个包含以下字段的数据库 ID、客户 ID、日期时间、数据 数据将是联系表单的 html。但我确信这不是最佳实践。此外,它不允许我向客户提供 csv 或类似形式的所有联系表格的下载选项。 我也不想为每个客户提供不同的表,而且我确信拥有一个包含“field1”、“field2”、“field3”等的表也不是那么好。 有什么想法吗?

I'm sorry if this a stupid question, but I am new to this. I want to store all the information from all my customers' different contact forms in a database so they can retrieve the information later. Each contact form has a different number of fields. Ideally I'd store all of this info in one MYSQL table, but as I said each customer's contact form has a different number of fields.

I was thinking of creating a database with the following fields
ID, customerID, dateTime, data
The data would be the html of the contact form. However I am sure that's not best practice. Also it wouldn't allow me to offer a download option to the customer of all their contact forms as a csv or similar.
I don't want to have a different table for each customer either, and I am sure having a table with 'field1', 'field2', 'field3' etc isn't that good either.
Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木槿暧夏七纪年 2024-11-21 15:48:57

如果你不需要它是关系性的,那就没问题了。您将无法很容易地查询它。

您可以使用键将答案存储在另一个表中以链接回表单和字段。

或者使用像 MongDB 这样的 KeyValue 存储类型数据库,您可以存储所有数据而无需担心架构。

If you don't need it to be relational, that would be fine. You wouldn't be able to query it very easily.

You could store the answers in another table using keys to link back to the form and field.

Or use a KeyValue store type DB like MongDB, and you could store all your data without worrying about the schema.

岁月流歌 2024-11-21 15:48:57

创建另一个表,名为 user_data。其中,有:

id, user_id, data

那么,如果他们填写了包含 10 个字段的表格,则您可以在该表中输入 10 个条目。当您为用户提取数据时,只需从 user_data 表中提取 user_id = 他们的 id 的任何数据即可。

如果您需要更多,您还可以添加“field_name”字段或其他内容:

id, user_data, field_name, data

Make another table called user_data. In it, have:

id, user_id, data

Then, if they fill out a form with 10 fields, you can enter 10 entries into this table. When you pull data for the user, just also pull any data from the user_data table that has user_id = their id.

If you need more than that, you could also add a "field_name" field or something:

id, user_data, field_name, data
向日葵 2024-11-21 15:48:57

您可以使用 MySQL 数据库为您所需的信息建立一个架构,将许多表相互关联。

这是关于数据库设计的另一个讨论:
数据库设计最佳实践

如果您必须只有一个表,我要提到的另一个选择是自动创建 ID,然后将字段设为不需要。这样,当客户先填写一张表格时,就不会打扰您了。然后,您可以将该 ID 存储为会话变量,并将其重新用于数据库的不同 INSERT 语句。

您可以为客户创建一个下载功能,该功能将以所需的格式输出,查询您的表,然后生成文件。

You can use the MySQL database to have a schema for your desired information that relates many tables to one another.

Here is another discussion about database design:
Database Design Best Practices

If you must have only one table, the other choice I would mention is to have the ID created automatically, and then make the fields be not required. This way when a customer fills out one form before the other it won't mess you up. You can then store the ID as a Session Variable and reuse it for different INSERT statements to your database.

You can make a download function for the customer that will output in the desired format that queries your table and then generates the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文