drdyf42880 2015-06-16 11:03
浏览 28
已采纳

使用ifignwith codeigniter返回值

I am using codeigniter framework for one of my inventory management systems. I prefer using php due to its variable functionality which makes things easier.

So I am trying to get the username from session and then check the database for the level of the user and accordingly he should be able to view links in the navigation menu.

$this->db->select('level');
$this->db->where('name', $this->session->userdata('name'));
$query = $this->db->get('admin');

if ($query) {
    foreach ($query->result() as $row)
{
    echo $row->level ;

}
}

This works fine and gets the level of the logged in user. Now I want to use a if condition with this value, so I am using this -

if ($this->$row->level = '3') {

?>
                        <li class="">
                            <a href="http://example.com/crm/emp_rep1.php">Employee Sales Report</a>
                        </li> 

<?php } ?>

But nothing seems to happen here, No error or any notice.

I have no clue what I am doing wrong here.

  • 写回答

1条回答 默认 最新

  • dongzhang4301 2015-06-16 11:21
    关注
    if ($this->$row->level = '3') {
    
    ?>
                            <li class="">
                                <a href="http://example.com/crm/emp_rep1.php">Employee Sales Report</a>
                            </li> 
    
    <?php } ?>
    

    you shouldn't use = operation for equal. should use == or === for equal. by that code you put 3 $this->$row->level and make it's value 3.

    if ($this->$row->level == '3') {
    
    ?>
                            <li class="">
                                <a href="http://example.com/crm/emp_rep1.php">Employee Sales Report</a>
                            </li> 
    
    <?php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题