I am having problem to display correct numbers of count(field). I am trying to group by field and want to return order by group and count of them.
controller is
$this->load->library('pagination');
$query = "SELECT usercode,count(usercode) AS co FROM tabs
GROUP BY usercode ORDER BY co desc";
$config['total_rows'] = $this->db->query($query)->num_rows();
$config['num_links'] = '25';
$config['uri_segment'] = 3;
$config['base_url'] = base_url() . "/user/topCreators/";
$config['per_page'] = '25';
$config['anchor_class'] = " class=\"number\" ";
$config['cur_tag_open'] = "<a href=\"#\" class=\"number
current\" title=\"Current Page\">";
$config['cur_tag_close'] = "</a>";
$this->pagination->initialize($config);
if ($this->uri->segment(3) == FALSE){
$offset = 0;
}
else
{
$offset = $this->uri->segment(4);
}
$limit = $config['per_page'];
$data["total_records"] = $config['total_rows'];
$data["page_links"] = $config["per_page"];
$data["query"] = $this->db->query($query . " LIMIT $limit OFFSET $offset");
$this->load->view("top_creators", $data);
my view file is
<?php foreach($query->result() as $me) {?>
<?= $me->co?>
<?php }?>