Codeigniter – Code Igniter Active Record – Num Rows & Results

codeigniter

$query = $this->db->select('*')->from($this->table)->order_by($sql);

The CI documentation isn't clear about this and I'm not entirely sure how this should work… if I have this query and need to check the num_rows() AND get results in an array. How would I do that?

When I use $this->db->select('*')->from($this->table)->order_by($sql)->get(); I'm not able to check num_rows()

Ideally I'd use result_array() to get the results in an array.

Best Answer

Try to use this

$query = $this->db->order_by('column name')->get('your tablename');

//note that your result must be an object

$count = $query->num_rows();//your num rows result handler

$result = $query->result_array();//your query result
Related Topic