Php CodeIgniter模型无法返回特定记录

Php CodeIgniter模型无法返回特定记录,php,mysql,codeigniter,model,rows,Php,Mysql,Codeigniter,Model,Rows,我正在使用CodeIgniter,当使用results()方法从表中获取所有行时,我无法使where()选择方法工作 这是我的模型: public function get_all_entries($id) { // Select row to be fetched $this->db->where('id', $id); $this->db->get('users'); // Execute the

我正在使用CodeIgniter,当使用
results()
方法从表中获取所有行时,我无法使
where()
选择方法工作

这是我的模型:

public function get_all_entries($id)
    {
        // Select row to be fetched
        $this->db->where('id', $id);
        $this->db->get('users');
        // Execute the find query with provided data
        $query = $this->db->get('users');
        // Return an object with all the data
        return $query->result();
    }
它应该返回与
users
表中的
$id
参数匹配的所有行,但它只是获取表中的所有记录,包括与提供的
$id
参数不匹配的记录


我做错了什么?我尝试了
row()
方法,虽然它与
where()
一起工作,但它只返回一行,因此不适合我的情况。

问题是您调用get()方法两次,第一次调用带有where的方法,但没有分配给变量;第二个被分配给一个变量,但是由于where子句已经被另一个使用,所以它得到了所有信息。删除第一个get,您就可以了

public function get_all_entries($id)
{
    // Select row to be fetched
    $this->db->where('id', $id);
    // Execute the find query with provided data
    $query = $this->db->get('users');
    // Return an object with all the data
    return $query->result();
}

我试过了,但有另一个问题(如果id为零或不在表中)让我认为这不是解决方案,现在我解决了这个问题,您提到的解决方案很有效,谢谢。请您对这个问题投赞成票好吗?非常感谢。