Welcome Guest, Not a member yet? Register   Sign In
No results when paginate (WHERE something=$something)

[eluser]Gabriel P[/eluser]

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:
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;
        if ($this->uri->segment(3) !== FALSE)
        $data['query'] = $this->db->get();

        $config['base_url'] = 'my_base_url';
        $config['total_rows'] = $total_rows;
        $config['per_page'] = $per_page;

        $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.


[eluser]Phil Sturgeon[/eluser]
Well you are not accepting the offset value in the controller if I understand you correctly. You are referencing segment 3 but it seems a little odd.

Here's how mine works:

function index($limit = 25, $offset = 0)
        $data['list'] = $this->test_model->getList($limit, $offset);
        // Pagination code
        $config['base_url'] = '/page/list/'.$limit.'/';
        $config['total_rows'] = $this->db->count_all('Table');
        $config['per_page'] = $limit;
        $config['uri_segment'] = 4;
        $data['pagination'] = $this->pagination->create_links();
        //... make page


Yours would be no different, simply add in your count with a WHERE and add an extra $catID to the start of the controller param list.

Theme © iAndrew 2016 - Forum software by © MyBB