查询返回数据,即使在codeigniter中语句为False时也是如此

时间:2015-10-29 07:56:30

标签: php mysql codeigniter

我面临的问题是即使语句为false,我的sql查询也会返回值。以下是我的代码: -

控制器: -

public function seller_edit_profile()
{
    if($this->userlib->isLoggedIn())
    {
        if($this->userlib->isAdmin())
        {
            $id2 = $this->userlib->getId();
            $id['admin_data'] = $this->admin_panel_model->admin_data($id2);
            $id['data'] = $this->admin_panel_model->seller_edit_data();
            $this->load->view('seller_edit_data', $id);
        }
        else
        {
            echo "User not Authorised";
        }
    }
    else
    {
        echo "User not Logged In";
    }
}

模型: -

public function seller_edit_data()
{
    $query = $this->db->select('*')
                      ->from('seller_details')
                      ->join('seller', 'seller.id = seller_details.id')
                      ->join('bank_details', 'seller_details.id = bank_details.id' )
                      ->join('store_details', 'seller_details.id = store_details.id')
                      ->where(array('seller.admin_check'=>6, 'seller.isAdmin'=>0))
                      ->or_where(array('seller.admin_check'=>7, 'seller.isAdmin'=>0))
                      ->get();
    return $query->result();              
}

之前,显示admin_check = 7的数据,但当我将状态更改为admin_check = 0时,不应在视图文件中看到" seller_edit_data"但它已经在这里展示了。

或者为了简单理解,当我显示$ id ['数据']我从数据库中获取了理想情况下不应该存在的值。

感谢提前1

2 个答案:

答案 0 :(得分:1)

试试这个

$query= $this->db->query("SELECT * FROM seller INNER JOIN seller_details ON 'seller.id=seller_details.id' INNER JOIN bank_details ON 'seller.id=bank_details.id' INNER JOIN store_details ON 'seller.id=store_details.id' where 'seller.admin_check' = 6 OR 'seller.admin_check' = 7 ");
$result = $query->result_array();
return $result;

将数据返回到控制器时使用result_array

答案 1 :(得分:0)

问题已解决,查询存在问题,我自己已经解决了。 用

替换模型中的查询
$query = $this->db->query("SELECT * FROM seller INNER JOIN seller_details ON 'seller.id=seller_details.id' INNER JOIN bank_details ON 'seller.id=bank_details.id' INNER JOIN store_details ON 'seller.id=store_details.id' where 'seller.admin_check' = 6 OR 'seller.admin_check' = 7 ");

并显示正确的结果。