CodeIgniter Forums
is pagination automatic? - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: is pagination automatic? (/thread-20848.html)

is pagination automatic? - El Forum - 07-23-2009

If I have this code in my controller (index):

$data['title'] = 'My New Title';
        $data['heading'] = 'My New Heading';
        $data['query'] = $this->Product_model->get_products();

        $config['base_url'] = '';
        $config['total_rows'] = $this->db->count_all('tblproducts');
        $config['per_page'] = '5';
        $config['uri_segment'] = 4;

        echo $this->pagination->create_links();

Is that all I need or do I need a page that actually does database work to get paging to work? I ask because this brings back all the data each time instead of just five rows. I have 30k that come back each time.

is pagination automatic? - El Forum - 07-23-2009

you need to pass a limit and offset to your get_products function. Limit is your per_page value and offset is will be in uri segment 4, based on your pagination setup above.

hope that helps.

is pagination automatic? - El Forum - 07-24-2009

Snippet from one of mine if it helps make it a little clearer... ;-)
$data['pagination'] = $this->pagination->create_links();

// get paginated results
$num = $config['per_page'];
$offset = $this->uri->segment(3);
$data['rows'] = $this->Categories->getPaginated($num, $offset);

$this->load->view('vw_viewCategories', $data);