• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination not working

#1
[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

#2
[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)?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.