Search code examples
phpmysqlcodeignitercodeigniter-3

unable to count the result with a condition using codeigniter query


I am trying to count rows of bookdetails table where display_id is as argument. Say i passed $id='3'. But i am not getting the output. I think the code which i am trying is wrong. Please help me to write this query correctly

  //--- Counting the rows of bookdetails of table where display_id is as argument------------------------------------------------------------- 
 public function record_count_for_secondtopBooks($id) {
     $this->load->database(); 
    return $this->db->count_all("bookdetails",array('display_id'=>$id)); 
}

Solution

  • $this->db->where('display_id',$id);
    $result = $this->db->count_all("bookdetails");
    

    or Chain em'

    $result = $this->db->where('display_id',$id)->count_all("bookdetails");
    

    check:

    echo'<pre>';
    print_r($result);
    echo'</pre>';