Codeigniter从结果row()获得2列

时间:2018-07-16 11:26:21

标签: php mysql codeigniter

我似乎找不到有关如何正确执行此操作的文档...我不能从结果行中提取2列吗?

我的用户模型

// log user in
    public function login($email, $password){
        // validate
        $this->db->where('email', $email);
        $this->db->where('password', $password);

        $result = $this->db->get('users');

        if($result->num_rows() == 1){
            return $result->row(0)->user_id;
            return $result->row(2)->gamertag;
        } else {
            return false;
        }

1 个答案:

答案 0 :(得分:2)

public function login($email, $password){
    // validate
    $this->db->select('user_id,gamertag');
    $this->db->where('email', $email);
    $this->db->where('password', $password);
    $this->db->from('users');
    $result = $this->db->get();

    if($result->num_rows() == 1){
        return $result->row();

    } else {
        return false;
    }