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

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

问题描述

我是新的codeigniter,我试图创建分页我从数据库中获取的记录。我写了以下代码,它显示我的分页,但它不影响结果集,我仍然有同一页上的所有记录,当我点击 Page2 它说未找到页面

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

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

VIEW

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


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

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


推荐答案

控制器:

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天全站免登陆