difference between $query>num_rows() and $this->db->count_all_results() in CodeIgniter & which one is recommended

后端 未结 8 1680
南方客
南方客 2020-12-13 17:50

In a scenario I need to know the count of recordset a query will return, which in codeigniter can be done by $query->num_rows() or $this->db->cou

8条回答
  •  生来不讨喜
    2020-12-13 18:25

    Simply as bellow;

    $this->db->get('table_name')->num_rows();
    

    This will get number of rows/records. however you can use search parameters as well;

    $this->db->select('col1','col2')->where('col'=>'crieterion')->get('table_name')->num_rows();
    

    However, it should be noted that you will see bad bad errors if applying as below;

    $this->db->get('table_name')->result()->num_rows();
    

提交回复
热议问题