gpt4 book ai didi

php - 如何在 Codeigniter 中创建分页?

转载 作者:行者123 更新时间:2023-11-29 04:21:20 25 4
gpt4 key购买 nike

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

请指导我如何创建分页?

型号

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

}

查看

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


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

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

最佳答案

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

}

关于php - 如何在 Codeigniter 中创建分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23101513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com