我的英语不好,很抱歉任何错误。我正在尝试使用codeigniter分页库,但我遇到了一个问题,它创建了额外的链接。我的数据在两个页面中完成,但当我点击第3或第4个链接时出现错误,底部出现4个页面链接。 这是我的控制器代码..
public function usr_list(){
$config = array();
$config["base_url"] = base_url() . "usr/usr_list";
$config["total_rows"] = $this->ListModel->record_count();
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->ListModel->getUser($config["per_page"] , $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('userList' , $data);
}
这是我的模型代码
function getUser($limit , $start){
$this->db->select("u_id,name,email,phone,cnic");
$this->db->from('user');
$this->db->limit($limit , $start);
$query = $this->db->get();
if($query->num_rows() > 0) {
foreach ($query->result() as $rows) {
$data[] = $rows;
}
return $data;
}
return false;
}
有什么建议吗?
答案 0 :(得分:2)
您的record_count()
函数返回'attendence'表中的条目数,而分页表中显示的数据来自'user'表(getUser
函数)。
“关注”表可能会有比“用户”表中更多的记录,这会为您提供额外的分页链接。
更改您的record_count()函数,如下所示。
public function record_count() {
return $this->db->count_all('user');
}