I am building a website of engineering and construction in which I have list of products such as bridge, towers and all are linked. When the user clicks on bridge then its type appears from mysql table on the same page which is in the form of image but the problem is again I want to retrieve the value i.e. its sub-types which are also images. And then when user clicks that image its details will be appeared. Basically its a hierarchy up to 3-4 levels. But don't know how to make relationships between tables.
我正在建设一个工程和建筑的网站,其中我有产品列表,如桥梁,塔楼和所有链接。当用户点击桥接时,它的类型出现在同一页面上的mysql表格中,该页面是图像形式,但问题是我想要检索该值,即它的子类型也是图像。然后,当用户点击该图像时,将显示其详细信息。基本上它的层次结构可达3-4级。但不知道如何在表之间建立关系。
3 个解决方案
#1
0
If the items in your hierarchy can be generalized enough, you could make a single table with the columns: id, parent, information
如果层次结构中的项目可以足够通用,则可以使用以下列创建单个表:id,parent,information
One entry could be id=Bridge, Parent=Architecture, information=picture_source
一个条目可以是id = Bridge,Parent = Architecture,information = picture_source
You can then make lookups like, show me every entry that has Architecture as its parent and send the list to the client.
然后,您可以进行查找,向我显示将Architecture作为其父项的每个条目,并将列表发送给客户端。
#2
0
Use InnoDB
engine for mysql. MyISAM
don't support foreign keys (if you are using the default).
使用InnoDB引擎的mysql。 MyISAM不支持外键(如果使用默认值)。
you can use:
您可以使用:
ALTER TABLE table_name ENGINE=InnoDB;
#3
0
use parent -child relationships like this,
example:
像这样使用parent -child关系,例如:
- when clicked on bridge - take data from child 1 table having same fk-key from main table , so your all bridge types will appear
- Do same for all your sub items
当点击桥接时 - 从主表中获取具有相同fk-key的子1表中的数据,因此将显示所有桥类型
对所有子项执行相同操作
#1
0
If the items in your hierarchy can be generalized enough, you could make a single table with the columns: id, parent, information
如果层次结构中的项目可以足够通用,则可以使用以下列创建单个表:id,parent,information
One entry could be id=Bridge, Parent=Architecture, information=picture_source
一个条目可以是id = Bridge,Parent = Architecture,information = picture_source
You can then make lookups like, show me every entry that has Architecture as its parent and send the list to the client.
然后,您可以进行查找,向我显示将Architecture作为其父项的每个条目,并将列表发送给客户端。
#2
0
Use InnoDB
engine for mysql. MyISAM
don't support foreign keys (if you are using the default).
使用InnoDB引擎的mysql。 MyISAM不支持外键(如果使用默认值)。
you can use:
您可以使用:
ALTER TABLE table_name ENGINE=InnoDB;
#3
0
use parent -child relationships like this,
example:
像这样使用parent -child关系,例如:
- when clicked on bridge - take data from child 1 table having same fk-key from main table , so your all bridge types will appear
- Do same for all your sub items
当点击桥接时 - 从主表中获取具有相同fk-key的子1表中的数据,因此将显示所有桥类型
对所有子项执行相同操作