我尝试从数据库进行动态菜单导航,但是变量$resCSM
在<?php if($sm['dd'] == 1) ;?>
之后不能通过,而是给了我array(0){}。但是当我尝试在其之前进行销售时,$resCSM
返回我想要的值。
这是代码:
<?php
$role_id = $this->session->userdata('role_id');
$queryM = "SELECT `menu`.`id`,`nmmenu`
FROM `menu` JOIN `us_access`
ON `menu`.`id` = `us_access`.`mid`
WHERE `us_access`.`ri` = $role_id
ORDER BY `us_access`.`mid` ASC
";
$menu = $this->db->query($queryM)->result_array();
?>
<?php foreach ($menu as $m) : ?>
<div class="sidebar-heading">
<?= $m['nmmenu']; ?>
</div>
<?php
$querySM = "SELECT `smenu`.* , `sm_us_access`.*
FROM `smenu` JOIN `sm_us_access`
ON `smenu`.`id` = `sm_us_access`.`smid`
WHERE `smenu`.`m_id` = {$m['id']}
AND `smenu`.`is_active` = 1 AND `sm_us_access`.`ri` = $role_id AND `sm_us_access`.`r` =1
ORDER BY `smenu`.`id` ASC ";
$resSM = $this->db->query($querySM)->result_array();
?>
<?php foreach ($resSM as $sm) : ?>
<?php
$queryCSM = "SELECT `csmenu`.*, `smenu`.*
FROM `csmenu` JOIN `smenu`
ON `csmenu`.`smid` = `smenu`.`id`
WHERE `csmenu`.`smid` = {$sm['id']}
";
$resCSM = $this->db->query($queryCSM)->result_array();
?>
<?php if ($sm['dd'] == 1) : ?>
<?= var_dump($resCSM) ?>
<li class="nav-item">
<a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseUtilities" aria-expanded="true" aria-controls="collapseUtilities">
<i class="fas fa-fw fa-wrench"></i>
<span><?= $sm['tm']; ?></span>
</a>
<div id="collapseUtilities" class="collapse" aria-labelledby="headingUtilities" data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<?= var_dump($resCSM) ?>
<!-- child submenu -->
<?php foreach ($resCSM as $csm) : ?>
<?= var_dump($csm) ?>
<a class="collapse-item" href="utilities-color.html"><?= $csm['nmmenu']; ?></a>
<?php endforeach; ?>
</div>
</div>
</li>
<?php else : ?>
<li class="nav-item">
<a class="nav-link pb-0 pt-0" href="<?= base_url($sm['url']) ?>">
<i class="<?= $sm['icon'] ?>"></i>
<span><?= $sm['tm'] ?></span></a>
</li>
<?php endif; ?>
<?php endforeach; ?>
<hr class="sidebar-divider mt-2">
<?php endforeach; ?>
查询没有问题,只是我不知道为什么<?php if($sm['dd'] == 1) ;?>
我希望有人可以帮助我解决此问题