How to create Pagination in Codeiginter?(如何在 Codeiginter 中创建分页?)
本文介绍了如何在 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 中创建分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在 Codeiginter 中创建分页?
基础教程推荐
猜你喜欢
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01