当我在我的codeigniter分页的第一页时,我的结果应显示显示1到1的3(3页)当前第一页从0开始显示0到0共3页(3页)
页码是uri段(3)。如何修复我的代码,使第一页为1 显示1到1的3(3页)
$page_number = $this->uri->segment(3);
if (isset($page_number)) {
$page = $page_number;
} else {
$page = 1;
}
$paginations_lang = "Showing %d to %d of %d (%d Pages)";
$data['results'] = sprintf($paginations_lang, ($user_group_total) ? (($page - 1) * $admin_limit) + 1 : 0, ((($page - 1) * $admin_limit) > ($user_group_total - $admin_limit)) ? $user_group_total : ((($page - 1) * $admin_limit) + $admin_limit), $user_group_total, ceil($user_group_total / $admin_limit));
控制器:
public function index($offset = 0) {
$this->load->model('admin/user/model_user_group');
$this->load->library('pagination');
$data['title'] = "Users Group";
$success = $this->session->userdata('success');
if (isset($success)) {
$data['success'] = $this->session->userdata('success');
$this->session->unset_userdata('success');
} else {
$data['success'] = '';
}
$page_number = $this->uri->segment(3);
if (isset($page_number)) {
$page = $page_number;
} else {
$page = 1;
}
$admin_limit = 1;
$user_group_total = $this->model_user_group->getTotalUserGroups();
$results = $this->model_user_group->getUserGroups($admin_limit, $this->uri->segment(3));
$config['base_url'] = base_url() . 'admin/users_group';
$config['total_rows'] = $user_group_total;
$config['per_page'] = $admin_limit;
$config['uri_segment'] = 3;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
foreach ($results as $result) {
$data['user_groups'][] = array(
'user_group_id' => $result['user_group_id'],
'name' => $result['name'],
'edit' => site_url('admin/users_group/edit' .'/'. $result['user_group_id'])
);
}
$paginations_lang = "Showing %d to %d of %d (%d Pages)";
$data['results'] = sprintf($paginations_lang, ($user_group_total) ? (($page - 1) * $admin_limit) + 1 : 0, ((($page - 1) * $admin_limit) > ($user_group_total - $admin_limit)) ? $user_group_total : ((($page - 1) * $admin_limit) + $admin_limit), $user_group_total, ceil($user_group_total / $admin_limit));
$this->load->view('template/user/users_group_list.tpl', $data);
}
答案 0 :(得分:0)
我已经解决了结果。
需要进行更改,因此第1页将会出现在第0页
旧
if (isset($page_number)) {
$page = $page_number;
} else {
$page = 1;
}
新
if (isset($page_number)) {
$page = $page_number;
} else {
$page = 0;
}
<强>结果强>
旧
$paginations_lang = "Showing %d to %d of %d (%d Pages)";
$data['results'] = sprintf($paginations_lang, ($user_group_total) ? (($page - 1) * $admin_limit) + 1 : 0, ((($page - 1) * $admin_limit) > ($user_group_total - $admin_limit)) ? $user_group_total : ((($page - 1) * $admin_limit) + $admin_limit), $user_group_total, ceil($user_group_total / $admin_limit));
新
$paginations_lang = "Showing %d to %d of %d (%d Pages)";
$data['results'] = sprintf($paginations_lang, ($user_group_total) ? (($page - 0) * $admin_limit) + 1 : 0, ((($page - 0) * $admin_limit) > ($user_group_total - $admin_limit)) ? $user_group_total : ((($page - 0) * $admin_limit) + $admin_limit), $user_group_total, ceil($user_group_total / $admin_limit));