使用codeigniter中的where where计算非null值

时间:2016-10-17 20:02:48

标签: php codeigniter

我正在编写一个函数来计算带有where条件的null列,但是这个函数存在问题

process.env.DATABASE_URI

此功能进行了查询

protected function _get_mcq_attept_count2( $mcq_id){
    $this->load->model('museranswer');  
    return $this->museranswe>count_by(array('mcq_id'=>$mcq_id,'bookrefrence!='=>" "));
}

此查询返回空列值

3 个答案:

答案 0 :(得分:0)

array("mcq_id" => "$mcq_id", "bookrefr‌​ence IS NOT NULL" => null)一样更改您的查询。希望你能得到正确的答案。如果它不起作用,请与我们分享您的模型。

答案 1 :(得分:0)

I hope this code work for it bcz in code-igniter i always use like this .

 protected function _get_mcq_attept_count2($mcq_id)
    {
        $this->load->model('museranswer');  
        $where = array('mcq_id'=>$mcq_id);
        return $this->museranswe>count_by($where);
    }

    /******************* FOR MODEL *********************/

    public function count_by($where)
    {
        $this->db->select('count(mcq_id) as numrows');
        $this->db->from('user_answer');
        $this->db->where($where);
        $this->db->where('bookrefrence !=',' ');

        $qry = $this->db->get();
        return $qry->result_array();
    }

答案 2 :(得分:0)

返回$ this-> museranswer-> count_by(array('mcq_id'=> $ mcq_id,'length(bookrefrence)> 2'));