dsf12313 2010-05-07 06:34
浏览 55

Codeigniter - 如何使用一个表中的外键来查找另一个表的id

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. 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:

id, button1, button2, button3, button4, region. (the buttons are all foreign keys leading to a separate buttons table)

  • 写回答

1条回答 默认 最新

  • duanfuxing2212 2010-05-07 20:50
    关注

    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.

    In the former case, your model would have two functions - a select from NavItem, and a select from buttons. 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.

    In the latter case, you only have to have one model function that runs one query, albeit not a trivial one.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用