[英]Codeigniter - how to use the foreign keys from one table to look for the id's of another table
I'm having a problem trying to wrap my head around how to query the database to retrieve the foreign keys in my Nav table and then using those to find the id's in the NavItem table. 我在尝试如何查询数据库以检索Nav表中的外键,然后使用这些键在NavItem表中查找id时遇到问题。 Can someone point me in the right direction or give me some pointers?
有人可以指出我正确的方向还是给我一些指示? i'm not even sure if this should be done in the model or the controller!
我什至不确定这是否应该在模型或控制器中完成!
Thanks in advance 提前致谢
EDIT 编辑
My NavItem table looks like this: 我的NavItem表如下所示:
id, button1, button2, button3, button4, region. id,button1,button2,button3,button4,区域。 (the buttons are all foreign keys leading to a separate buttons table)
(按钮都是通向单独按钮表的外键)
You have to either query the buttons table four times, once for each of button1-button4, or you have to join the button table four times in your select from NavItem. 您必须查询按钮表四次,每个按钮1-button4一次,或者必须在NavItem的选择中联接按钮表四次。
In the former case, your model would have two functions - a select from NavItem, and a select from buttons. 在前一种情况下,模型将具有两个功能-从NavItem中进行选择,以及从按钮中进行选择。 You call the select from NavItem function from your controller, and use the data it returns to run the select from buttons function four times, also from the controller.
您从控制器调用NavItem函数中的select,并使用它返回的数据运行四次(也从控制器)按钮选择中的功能。
In the latter case, you only have to have one model function that runs one query, albeit not a trivial one. 在后一种情况下,您只需要具有一个模型函数即可运行一个查询,尽管它不是琐碎的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.