如何在 Codeiginter 中创建分页? [英] How to create Pagination in Codeiginter?

查看:22
本文介绍了如何在 Codeiginter 中创建分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 codeigniter 的新手,我正在尝试在我从数据库中获取的记录上创建分页.我编写了以下代码,它显示了分页,但不影响结果集,我仍然在同一页面上保存所有记录,当我单击 Page2 时,它说 no page found.

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?

模型

public function students_list()
{


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

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

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

    return $query->result();

    }

控制器

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);

}

查看

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


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

foreach($students_data as $teachers_records)
{
    ...
     ....

推荐答案

Controller:

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);
    }

型号

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();

 }

这篇关于如何在 Codeiginter 中创建分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆