1

I am writing a function to count the null column with where condition but there is a problem in this function

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

this function made the query

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

this query return the empty column value

Pathik Vejani
  • 4,263
  • 8
  • 57
  • 98
Sourabh Kumar
  • 94
  • 3
  • 15

3 Answers3

1
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();
    }
0

Change your query like this array("mcq_id" => "$mcq_id", "bookrefr‌​ence IS NOT NULL" => null). Hope you will get right answer. If it does not work, share your model with us.

Jobayer
  • 1,221
  • 1
  • 14
  • 22
0

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

Sourabh Kumar
  • 94
  • 3
  • 15