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



Pagination - El Forum - 12-27-2010

[eluser]praveena[/eluser]
HI
I am creating a pagiantion for my page I have a problem I was not able to create a link for second page
this is my code
CONTROLLER CODE
function index($row=0)
{
$this->load->model('page_model');
$this->load->library('pagination');
$config['base_url']='base_url()';
$config['total_rows']=$this->page_model->studentcount();
$config['per_page']='3';
$this->pagination->initialize($config);
$data['title']='Displaying Student List';
$data['list']=$this->page_model->getstudents();
$data['header']='Student List';
$data['links']=$this->pagination->create_links();
//$mem['list']=$this->page_model->getstudents();
$this->load->view('page_viewall',$data);
}
*********************************************************************************

Pls help me


Pagination - El Forum - 12-27-2010

[eluser]InsiteFX[/eluser]
Code:
function index($row = 0)
{
    $this->load->model('page_model');
    $this->load->library('pagination');

    $config['base_url']    = 'http://yousite.com/index.php/function/page/';
    $config['total_rows']  = $this->page_model->studentcount();
    $config['per_page']    = '3';
    $config['uri_segment'] = 3;

    $this->pagination->initialize($config);

    $data['title']  = 'Displaying Student List';
    $data['list']   = $this->page_model->getstudents();
    $data['header'] = 'Student List';
    $data['links']  = $this->pagination->create_links();

    // $mem['list'] = $this->page_model->getstudents();
    $this->load->view('page_viewall', $data);
}

Read the CodeIgniter User Guide! Pagination Class

InsiteFX


Pagination - El Forum - 12-27-2010

[eluser]Federico BaƱa[/eluser]
your "getstudents" method should have a parameter to indicate the page you're loading, like this:
Code:
$page = $this->uri->segment(3); // get the page from the query string (url)
$this->page_model->getstudents($page); // pass the page over to the model

and your query could be like:

Code:
public function getstudents($page)
{
    $this->db->limit($page, 3); // narrow your query to only the rows on the page
    $query = $this->db->get('students'); // run query
    return $query->result(); // return results
}