在我的分页结果中,它显示不正确,例如它应该在视图上显示Showing 1 to 5 of 5 (1 Pages)
但由于某种原因它显示Showing -19 to 0 of 5 (1 Pages)
我不确定为什么显示-19应该显示1 $ $data['results']
无法正常工作如何修复它。
<?php
class Users_group extends MX_Controller {
public function index() {
$this->load->library('paginations');
$this->load->model('admin/user/model_user_group');
$data['title'] = "Users Group";
// Sort
if (null !==($this->uri->segment(3))) {
$sort = $this->uri->segment(3);
} else {
$sort = 'name';
}
// Order
if (null !==($this->uri->segment(4))) {
$order = $this->uri->segment(4);
} else {
$order = 'asc';
}
// Page
if (null !==($this->uri->segment(3))) {
$page = $this->uri->segment(3);
} else {
$page = 1;
}
$url = '';
// Sort
if (null !==($this->uri->segment(3))) {
$url .= $this->uri->segment(3);
}
// Order
if (null !==($this->uri->segment(4))) {
$url .= $this->uri->segment(4);
}
// Page Number
if (null !==($this->uri->segment(3))) {
$url .= $this->uri->segment(3);
}
$admin_limit = "20";
$filter_data = array(
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $admin_limit,
'limit' => $admin_limit
);
$user_group_total = $this->model_user_group->getTotalUserGroups();
$results = $this->model_user_group->getUserGroups($filter_data);
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'] . $url)
);
}
$url = '';
if ($order == 'asc') {
$url .= 'desc';
} else {
$url .= 'asc';
}
$data['sort_name'] = site_url('admin/users_group' .'/'. 'name' .'/'. $url);
$url = '';
$paginations = new Paginations();
$paginations->total = $user_group_total;
$paginations->page = $page;
$paginations->limit = $admin_limit;
$paginations->url = site_url('admin/users_group' .'/'. $url . '{page}');
$data['pagination'] = $paginations->render();
$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));
$data['sort'] = $sort;
$data['order'] = $order;
$this->load->view('template/user/users_group_list.tpl', $data);
}
public function getForm() {
$data['title'] = "Users Group";
$this->load->view('template/user/users_group_form.tpl', $data);
}
}