php 如何在 phpmyadmin 中显示外键的内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14104206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I display content for foreign keys in phpmyadmin
提问by Tales
Whenever I try to insert a new record in my MySQL database using phpMyAdmin, if the column refers to a foreign key, i get a dropdown box with the valid IDs that i can use. The problem is when the database gets too big, the ID is meaningless for me. For example if the ID is the social security number of the employee, i don't know it, but i can probably remember the name. Is there a way to display the row contents next to the ID or at least one column that could be more meaningful to the user? I have seen that feature in phpPgAdmin.
每当我尝试使用 phpMyAdmin 在我的 MySQL 数据库中插入新记录时,如果该列引用外键,我会得到一个下拉框,其中包含我可以使用的有效 ID。问题是当数据库变得太大时,ID 对我来说毫无意义。例如,如果 ID 是员工的社会安全号码,我不知道,但我可能记得名字。有没有办法显示 ID 旁边的行内容或至少一列对用户更有意义?我已经在 phpPgAdmin 中看到了该功能。
I tried this in the config file:
我在配置文件中试过这个:
$cfg['ForeignKeyDropdownOrder'] = array( 'content-id', 'id-content' );
But it didn't work.
但它没有用。
回答by EternalHour
phpmyadmin has a function for this.
phpmyadmin 有一个功能。
- Select the table that contains the foreign key (child).
- Click the "Structure" tab.
- Click "Relation view".
- Under the foreign key constraints, click the "Choose column to display" drop down and make a choice.
- 选择包含外键(子键)的表。
- 单击“结构”选项卡。
- 单击“关系视图”。
- 在外键约束下,单击“选择要显示的列”下拉菜单并进行选择。
The column value will now be shown next to the id. It will also be shown when hovering over the foreign key value after making a selection.
列值现在将显示在 id 旁边。在进行选择后将鼠标悬停在外键值上时也会显示它。
For anyone having trouble getting this setup, please see the #relation-viewdocumentation which tells you exactly how to configure it with screenshots.
对于在获取此设置时遇到问题的任何人,请参阅#relation-view文档,该文档准确地告诉您如何使用屏幕截图进行配置。
回答by iontomet
In addition to what @EternalHour says you also need to check the radio button under view options
除了@EternalHour 所说的,您还需要检查查看选项下的单选按钮
that says "Relational display column"if you want the value to be displayed.
上面写着“关系显示栏”如果你想显示的数值。
If not checked you will only see the Foreign Key value when you hover that specific id.
如果未选中,您将仅在悬停该特定 ID 时看到外键值。
回答by Olivier Van Bulck
If you really want to keep using phpmyadmin for this, you can create a view with a join which shows you the name, id and other information in 1 table. Then you can just use the search function to search on a name.
如果您真的想继续为此使用 phpmyadmin,您可以创建一个带有连接的视图,该视图显示 1 个表中的名称、ID 和其他信息。然后您可以使用搜索功能来搜索名称。

