使用ifignwith codeigniter返回值

时间:2015-06-16 11:03:12

标签: php codeigniter if-statement

我正在为我的一个库存管理系统使用codeigniter框架。 我更喜欢使用php,因为它具有可变功能,使事情变得更容易。

所以我试图从会话中获取用户名,然后检查数据库中的用户级别,因此他应该能够在导航菜单中查看链接。

$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 ;

}
}

这很好,并获得登录用户的级别。 现在我想使用带有此值的if条件,所以我使用了这个 -

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

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

<?php } ?>

但这里似乎没有发生任何错误或任何通知。

我不知道我在这里做错了什么。

1 个答案:

答案 0 :(得分:1)

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

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

<?php } ?>

你不应该使用= operation for equal。应该使用==或===等于。通过该代码,您将3 $ this-&gt; $ row-&gt;级别设为3,并将其设为值。

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

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

<?php } ?>