Codeigniter分页从不同页面和不同员工的不同活动链接开始,而代码相同

问题描述 投票:0回答:1

我有员工的出勤细节,我想用分页显示这些细节,但问题是分页从不同的页码开始。对于某些用户,它从第一页开始,而对于其他用户,它从第2页开始。虽然分页应该从每个用户的第一页开始。我不知道问题出在哪里。我比较新鲜。请指导我。

控制器:

public function attendance($biometric_reg_number) {

    $this->load->helper('form');
    $this->load->model('Attendance_model', 'attendances');
    $this->load->library('pagination');
    $config = [
        'base_url'        => base_url("admin/attendance/attendance/{$biometric_reg_number}"),
        'per_page'        => 30,
        'total_rows'      => $this->attendances->filter_attenceby_admin_num_rows($biometric_reg_number),
        'full_tag_open'   => "<ul class='pagination'>",
        'full_tag_close'  => "</ul>",
        'first_link'      => "First",
        'first_tag_open'  => '<li>',
        'first_tag_close' => '</li>',
        'last_link'       => 'Last',
        'last_tag_open'   => '<li>',
        'last_tag_close'  => '</li>',
        'next_tag_open'   => '<li>',
        'next_tag_close'  => '</li>',
        'prev_tag_open'   => '<li>',
        'prev_tag_close'  => '</li>',
        'num_tag_open'    => '<li>',
        'num_tag_close'   => '</li>',
        'cur_tag_open'    => "<li class='active'><a>",
        'cur_tag_close'   => '</a></li>',
    ];
    $this->pagination->initialize($config);
    $this->load->model('Attendance_model', 'attendances');
    $attendances = $this->attendances->find_attendance_detail($biometric_reg_number, $config['per_page'], $this->uri->segment(5));
    $this->load->view('admin/attendance', ['attendances' => $attendances]);
}

型号:

public function find_attendance_detail($biometric_reg_number, $limit, $offset) {
    $q = $this->db->select('*')
        ->from('basic_detail')
        ->join('employeedata', "employeedata.biometric_reg_number = basic_detail.biometric_reg_number")
        ->where('basic_detail.biometric_reg_number', $biometric_reg_number)
        ->limit($limit, $offset)
        ->order_by('employee_date', 'DESC')
        ->get();

    return $q->result();

}

public function filter_attenceby_admin_num_rows($biometric_reg_number) {
    $q = $this->db->select('*')
        ->from('basic_detail')
        ->join('employeedata', "employeedata.biometric_reg_number = basic_detail.biometric_reg_number")
        ->where('basic_detail.biometric_reg_number', $biometric_reg_number)
        //->order_by('employee_date','DESC')
        ->get();

    return $q->num_rows();
}

image

image 2 image 3

php mysql codeigniter pagination
1个回答
0
投票

你没有在$ config中设置uri_segment。

$config['uri_segment'] = 5

数字应该是页码,而不是实际的记录偏移量。如果未设置uri(5),则应在变量中设置页面。

$page = ($this->uri->segment(5)) ? ($this->uri->segment(5) - 1) : 0;

并使用$ page调用find_attendance_detail。

$attendances = $this->attendances->find_attendance_detail($biometric_reg_number, $config['per_page'], ($page * 30));

此外,您应该使用sql COUNT来获取总记录数,而不需要连接。

SQL有点像这样。

select count(*) from basic_detail 
where basic_detail.biometric_reg_number = $biometric_reg_number;

(我不使用CI查询构建器,所以我不知道确切的命令。)

© www.soinside.com 2019 - 2024. All rights reserved.