简体   繁体   English

我的主键被用作数据库表中的外键

[英]my primary key is used as foreign key in the table of my db

I have a scenario as seen below " record1: 我有一种情况,如下所示“ record1:

ID            2
MenuName      Our Team
MenuIcon      fa-globe
ParentID      1
MenuURL       /about/ourteam
MenuPosition  1
record2:
ID            1
MenuName      About
MenuIcon      fa-globe
ParentID      0
MenuURL       /about
MenuPosition  1

"

And follows same sequence for all the menu. 并对所有菜单遵循相同的顺序。 The problem is there are some that must not have a submenu I want to do a method that check if that parent menu name is equal to another set of names called products in another table then no sub menu should be attached. 问题是有些菜单必须没有子菜单,我想做一个方法来检查父菜单名称是否等于另一个表中称为产品的另一组名称,然后再不附加子菜单。

here is my code 这是我的代码

    <?php foreach($menus as $menu):?>

     <?php 
     if ($menu->name == $product->name){

     echo 'cannot attach sub-menu on product';

     }
     else {
     //call the add and detached submenu function
     }
    ?>

Am using codeigniter. 我正在使用codeigniter。 I have passed the record on the controller to a variable called $menus 我已将控制器上的记录传递给名为$menus的变量

using eloquent db function. 使用雄辩的db函数。 $menus = MenuModel::all();

Thanks in advance 提前致谢

如果您正在使用CI,请尝试:

$menues = $this->db->get('menus')->result()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM