每页记录允许用户选择 - codeigniter 分页 [英] records per page allow user to choose - codeigniter pagination
问题描述
我有有效的分页.我已将限制设置为每页 5 条记录,但我希望用户能够根据需要进行更改.问题是我不知道该怎么做.
I have pagination that works. I have set the limit to 5 records per page, but I will like the user to be able to change that if he want. Problem is i have no idea how to do it.
在视图中,我创建了下拉菜单,因此用户可以选择每页要查看的记录数:
In the view, I created drop down menu, so user can choose how many records he want to see per page:
<ul class="dropdown-menu">
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id="2" class="pPage" data-tableid="smpl_tbl">
2 records per page
</a>
</li>
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id ="50" class="pPage" data-tableid="smpl_tbl">
50 records per page
</a>
</li>
<li><a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id="100" class="pPage" data-tableid="smpl_tbl">
100 records per page
</a>
</li>
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id="all" class="pPage" data-tableid="smpl_tbl">
Display all records
</a>
</li>
</ul>
在我的控制器中,我有以下代码:
In my controller, I have the following code:
public function displayAllUsers()
{
$recordsPerPage = 5;
$limit = $recordsPerPage;
$offset = 3;
$offset = $this->uri->segment(3);
$this->db->limit($limit, $offset);
$data['users'] = $this->backOfficeUsersModel->get();
$totalresults = $this->db->get('back_office_users')->num_rows();
//initializing & configuring paging
$this->load->library('pagination');
$config['base_url'] = site_url('/backOfficeUsers/displayAllUsers');
$config['total_rows'] = $totalresults;
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<div class="dataTables_paginate paging_bootstrap pagination"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['cur_tag_open'] = '<li><a href=# style="color:#ffffff; background-color:#258BB5;">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['main_content'] = 'bousers/users';
$data['title'] = 'Back Office Users';
$errorMessage = FALSE;
$this->load->vars($data,$errorMessage);
$this->load->vars($currentUser);
$this->load->view('backOffice/template');
} // end of function displayAllUsers
谁能告诉我如何显示用户从下拉菜单中选择的记录数?如果他什么都不选,我想默认显示5条记录.
Can anyone tell me how can i display number of records that user selected from the drop down menu? If he doesn't select anything, I would like to display 5 records by default.
任何帮助将不胜感激.
问候卓然
推荐答案
你不应该做那样的下拉菜单.. 试试这个
You shouldn't make a drop down like that.. Try this instead
查看
echo form_open('controller/displayAllUsers');
$options = array(
'' => 'Select',
'2' => '2',
'50' => '50',
'100' => '100');
echo form_dropdown('sel',$options,'');
echo form_submit('submit',Submit);
控制器
if(isset($post['sel']) && !empty($post['sel']))
$config['per_page'] = $post['sel'];
else
$config['per_page'] = 5;
并且在执行此操作之前不要忘记加载 form helper .. 否则你可以给正统的 html select
框
And don't forget to load form helper before doing this.. Or else you can give orthodox html select
box
(另一种方式)
查看:
<ul class="dropdown-menu">
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers/2" class="pPage" data-tableid="smpl_tbl">
2 records per page
</a>
</li>
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers/50" class="pPage" data-tableid="smpl_tbl">
50 records per page
</a>
</li>
<li><a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers/100" class="pPage" data-tableid="smpl_tbl">
100 records per page
</a>
</li>
<li>
<a href="<?php echo base_url(); ?>backOfficeUsers/displayAllUsers" id="all" class="pPage" data-tableid="smpl_tbl">
Display all records
</a>
</li>
控制器:
public function displayAllUsers()
{
$currentUser = $this->isLoggedIn();
$this->load->model('backOfficeUsersModel');
$this->db->order_by('userid');
//$recordsPerPage = 5;
//$limit = $recordsPerPage;
if ($this->uri->segment(3) !="") {
$limit = $this->uri->segment(3);
} else {
$limit = 5;
}
$offset = 4;
$offset = $this->uri->segment(4);
$this->db->limit($limit, $offset);
$data['users'] = $this->backOfficeUsersModel->get();
这篇关于每页记录允许用户选择 - codeigniter 分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!