CodeIgniter Forums
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: Pagination not working (/showthread.php?tid=10979)



Pagination not working - El Forum - 08-21-2008

[eluser]sampada[/eluser]
Hi

I am just trying to use pagination library of codeignitor. I set up following code in controller

<?php
require_once('basecontroller.php');
class Productlist extends BaseController
{
function Productlist()
{
parent::BaseController();

}


function index()
{
$this->display();

}

function display()
{


$this->load->database();
$query=$this->db->query("Select * from coffee");

$this->load->library('pagination');
$config['base_url'] = 'LINK FOR PAGE TO BE PAGINATED';
$config['total_rows'] = '$query->num_rows()';
$config['per_page'] = '1';


$this->pagination->initialize($config);
$data['link']= $this->pagination->create_links();
$this->_render("rapyd/testview",$data);
}

}

?>


The links are displayed as 1 2 3, In first page it shows 3 rows and same for other pages also. I have got only 3 rows in coffee table. I need to show 2 rows on first page and thrd row in second page.

Can you help me on it? I have not used CI so much. So I got confused.

Thanks


Pagination not working - El Forum - 08-21-2008

[eluser]nevsie[/eluser]
i am a little confused about what you are saying here... plus it would make it easier to help if you put the code between code tags - makes it easier for old eyes to read!!!

now i am looking at your code and seeing that the only data you pass to the view is "link"... Is this correct?
I think i can also see that you setting the total number of links to be all results in the table, with a value of 1 result expected to be displayed.

This all make sense that when you display, if you have 3 rows in your database you will get links "1, 2, 3"... Remember pagination is only for the page links.

How are you actually displaying the results from your table, i.e. title, description, etc (or whatever fields you have)?