CodeIgniter Forums
Help pagination not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help pagination not working (/showthread.php?tid=26766)



Help pagination not working - El Forum - 01-22-2010

[eluser]farocco[/eluser]
Hi All,

What am I doing wrong?

I am getting more pages than is necessary.

Thanks

$config['base_url'] = 'http://localhost/ci/index.php?site/query/';
$config['per_page'] = '10';

$this->db->like("Size", $this->input->post('size'));
$data['query'] = $this->db->get('shopinventory',$config['per_page'],$this->uri->segment(3));

$config['total_rows'] = $this->db->count_all_results('shopinventory');

$this->pagination->initialize($config);
$data['main_content'] = 'site/list';

$this->load->view('includes/template', $data);


Help pagination not working - El Forum - 01-22-2010

[eluser]mattpointblank[/eluser]
In your first DB query you're asking for all records where the 'Size' field is LIKE $_POST['size'], whereas in your second query (where you get the total_rows) you get EVERYTHING. Alter it to include the 'Size' clause as well.


Help pagination not working - El Forum - 01-22-2010

[eluser]farocco[/eluser]
$config['base_url'] = 'http://localhost/ci/index.php?site/query/';
$config['per_page'] = '10';

$this->db->like("Size", $this->input->post('size'),'after');
$config['total_rows'] = $this->db->count_all_results('shopinventory');
$this->pagination->initialize($config);

$this->db->like("Size", $this->input->post('size'),'after');
$data['query'] = $this->db->get('shopinventory',$config['per_page'],$this->uri->segment(3));

$data['title'] = 'National Tire Warehouse';
$data['main_content'] = 'site/list';

$this->load->view('includes/template', $data);

This seems to work until I select next page, then I get all records.
I think I am losing the post value.

Is there an eaiser way to code this?

Thanks


Help pagination not working - El Forum - 01-25-2010

[eluser]mattpointblank[/eluser]
Yes, you are losing the post value - you can't preserve that over pages unless you store it in a session variable once you obtain it.