Counting the number of results returned by a database query in Codeigniter

后端 未结 6 1737
无人及你
无人及你 2021-01-12 15:53

I am not having much luck detecting when a database query in Codeigniter returns zero results. I have had a good read of the notes on the PHP count function but am none the

6条回答
  •  不知归路
    2021-01-12 16:07

    i'm dowing this and it workd for me

    Controller

    $id = $this->session->userdata('id');
    if($this->model_users->if_user_dont_have_email($id)){
    ....
    }
    

    Model Users

    public function if_user_dont_have_email($id){
        $query = $this->db->query("SELECT email FROM users WHERE id='$id'");
        if ($query->num_rows() > 0) {
            $row = $query->row_array(); 
            if(empty($row['email'])){
                return true;
            }else{
                return false;
            }
        }
    }
    

提交回复
热议问题