I have this function:
function gi_get_by($col,$id, $itd, $tbl, $limit = 10)
{
$this->db->select('*');
$this->db->from('global_info');
$this->db->join($tbl, 'id_' . $tbl . ' = id_global_info');
$this->db->where('info_type_id', $itd);
if($col == 'date_created' || $col == 'tag') {$this->db->like($col, $id);}
else {$this->db->where($col, $id);}
if($tbl == 'ad') :
$this->db->order_by('paid', 'desc');
endif;
$this->db->order_by('date_created', 'desc');
$this->db->limit($limit, $this->uri->segment(2));
$q = $this->db->get();
return $q = $q->result_array();
}
What I need is to count number of results before limit and to use them later in controller. I have an idea to duplicate this function without $limit but then it will be duplicating the same function. Is there another way to do this or I have to go with duplication?
I don’t quite understand what you want to do but if you want an optional limit you can default it to false:
This will conditionally add limit clause if it is passed in to the function.
Also it would be best to pass in wwhatever
$this->uri->segment(2)into the function as a parameter instead of accessing it from within the function.