Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
754 views
in Technique[技术] by (71.8m points)

php - How to create Pagination in Codeiginter?

I am new to codeigniter, I am trying to create pagination on the records i am fetching from database. I have written the following code, its showing me pagination but its not effecting the result set, I still have all the records on the same page and when i click on Page2 it says no page found.

Kindly guide me how to create pagination?

MODEL

public function students_list()
{


    $this->db->select('*');
    $this->db->from('student'); 

    $this->db->limit($limit,$start);                

    $query= $this->db->get();

    return $query->result();

    }

CONTROLLER

public function all_students()
{

    //Pagination    
            $this->load->library('pagination');

            $config['base_url'] = base_url().'mycontroller/all_students/';
            $config['total_rows'] = 200;
            $config['per_page'] = 5;

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

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

    //Pagination

    $this->load->model('loginmodel');
    $data['students_data']= $this->loginmodel->students_list();
    $data['dropdown']=      $this->loginmodel->get_degree_names();

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

}

VIEW

<?php
include 'header.php';
include 'sidebar.php';


$this->pagination->create_links();
?>
<?php 

foreach($students_data as $teachers_records)
{
    ...
     ....
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Controller:

public function all_students() 
 {      $this->load->model('loginmodel');
        $config['anchor_class'] = '';
        $config['show_count'] = true;
        $config['base_url'] = site_url('controllername/all_students');
        $config['total_rows'] = sizeof($this->loginmodel->students_list());

        $data['students_data']= $this->loginmodel->students_list();
        $data['dropdown']=      $this->loginmodel->get_degree_names();
        $config['per_page'] = 10;
        $this->jquery_pagination->initialize($config);
        $data['links'] = $this->jquery_pagination->create_links();
        $data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data['details'] = $this->loginmodel->students_list($config['per_page'], $data['page']);
        $this->load->view('all_students', $data);
    }

Model

public function students_list($limit=NULL,$start=NULL)
{


    $this->db->select('*');
    $this->db->from('student'); 

    $this->db->limit($limit,$start);                

    $query= $this->db->get();

    return $query->result();

 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...