是否有可能在mysql数据库的一列中发布两个数据? [英] is it possible to post two datas in one column in mysql database?

查看:76
本文介绍了是否有可能在mysql数据库的一列中发布两个数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是我想在一个表中发布两个数据,但我不知道是否可能。一列有什么办法可以同时处理两个或更多数据?



这是模态



例如,我有两个要用于本机的显示器。但是从数据库中我只能看到第一个字段而不是添加的字段被记录。如您所见,我具有一个小功能,可以在其中可以添加或删除多个类别的类别中添加和删除字段。



这是我要在其中发送数据的表

解决方案

您应该真正研究数据库规范化。
使用当前的表结构,没有有效的方法来执行所需的操作(因为您只有一个字段来存储每种类型的组件。
一种解决方法是转换可能包含多个字段的每个字段用户选择为JSON类型并将其存储在其中。(所需要做的就是构建 $ monitors 数组,然后将其转换为json(使用 json_encode($ monitors)插入之前。虽然可行,但在效率和可索引性/可搜索性方面还是有一些缺点





您应该有一个枢轴表(我们称其为装配体)和单独的零部件表(称它们为表)。
组装新设备时,您将创建一个新的 assembly,然后将组件插入其各自的表中,如下所示:
您想要的,但是可以是显示器, cpus,内存等。对主装配体表的引用
s,您可能只有一个程序集引用监视器表中的多个条目,因为此结构允许建立一对多关系



我强烈建议您双脚正常化。 Wikipedia可能是一个很好的起点这里



可以在 HERE 中找到更深入的示例解释p>

What I want to do is I want to post two datas in one table but I don't know if it's possible or not. Is there any way that a column can hadle two datas or more at once?

Here is the modal

Like for example I have two monitors that I want for my unit. But from what I can see from the database only the first field gets recorded not the added field. As you can see I have a little function where I can add and delete fields in categories where items can be multiple or not.

Here is my table that I want to send the datas in

解决方案

You should really look into database normalization. With your current table structure, there's no efficient way to do what you need (because you only have one field for storing each type of component. A workaround would be to convert each field that could potentially hold multiple user selections to a JSON type and store them there. (all it takes would be to build a $monitors array and then convert it to json (with json_encode($monitors) prior to inserting. This, while feasible, has some drawbacks in terms of efficiency and indexability/searchability

what you really need is, like I said earlier, normalizing your tables.

You should have a "pivot" table (let's call it "assemblies") and separate component tables (call them what you want, but it could be "monitors", "cpus", "memory" etc). When assembling a new device, you'd create a new "assembly" and insert the components in their respective table with a reference to the master "assemblies" table By doing this, you could have a single assembly referencing multiple entries in the "monitors" table because this structure allows establishing "one-to-many" relationships

I strongly suggest you get your feet wet with normalization. Wikipedia could be a good starting point HERE

A more in depth explanation with examples can be found HERE

这篇关于是否有可能在mysql数据库的一列中发布两个数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆