Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用codeigniter中的where条件计算not null值_Php_Codeigniter - Fatal编程技术网

Php 使用codeigniter中的where条件计算not null值

Php 使用codeigniter中的where条件计算not null值,php,codeigniter,Php,Codeigniter,我正在编写一个函数来计算where条件下的空列,但是这个函数有一个问题 protected function _get_mcq_attept_count2( $mcq_id){ $this->load->model('museranswer'); return $this->museranswe>count_by(array('mcq_id'=>$mcq_id,'bookrefrence!='=>" ")); } 此函数进行查询 SELE

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

protected function _get_mcq_attept_count2( $mcq_id){
    $this->load->model('museranswer');  
    return $this->museranswe>count_by(array('mcq_id'=>$mcq_id,'bookrefrence!='=>" "));
}
此函数进行查询

SELECT COUNT(*) AS `numrows`
FROM `user_answer`
WHERE `mcq_id` = '321'
AND `bookrefrence` != ' '

此查询返回空列值

按以下方式更改查询
数组(“mcq\u id”=>“$mcq\u id”,“bookrefr”‌​ence不为NULL“=>NULL)
。希望你能得到正确的答案。如果不起作用,请与我们共享您的模型。

返回$this->museranswer->count_by(数组('mcq_id'=>$mcq_id,'length(bookreference)>2')

选中此项:
$this->museranswe>count_by(数组('mcq_id'=>$mcq_id,'bookreference不为NULL')不工作,请给我其他解决方案。感谢您在
museranswe
模型中显示您的
count\u方法?
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();
    }