[eluser]Gabriel P[/eluser]
Hello,
I wish to grab some articles from db WHERE parentid=$catid. The thing is i want to paginate them. So, i believe i did not write the correct code.
Here is my function from the controller:
Code:
function showArtByCat($catid)
{
$data['base_url'] = $this->config->item('base_url');
$data['cats'] = $this->Catmodel->getCats();
$data['subcats'] = $this->Catmodel->getSubCats($catid);
$data['catname'] = $this->Catmodel->getCatName($catid);
$query = $this->db->query("SELECT COUNT(*) AS count FROM articles WHERE (parentid=".$catid.")");
$row = $query->row();
$total_rows = $row->count;
$per_page = 10;
$this->db->use_table('articles');
$this->db->limit($per_page);
if ($this->uri->segment(3) !== FALSE)
{
$this->db->offset($this->uri->segment(3));
}
$data['query'] = $this->db->get();
$config['base_url'] = 'my_base_url';
$config['total_rows'] = $total_rows;
$config['per_page'] = $per_page;
$this->pagination->initialize($config);
$data['paginate'] = $this->pagination->create_links();
$this->load->view('front/cat', $data);
}
Could somebody help me? I think i`m tired and i can`t figure it out.
Thanks,
Gabriel