这是我的分页代码。当我点击“下一步”按钮时,它会显示包含剩余产品图片的下一页,但是如果我点击“上一页”它会显示空白页面。我申请了另一页的相同代码分页其工作很好,但它不适合这个页面。
控制器
public function onSectorClick1() {
$id = $_GET["id"];
$this->session->set_userdata('subcategory2_id', $_GET['id']);
$this->session->set_userdata('subcategory2_name', $_GET['name']);
$this->onSectorClick1Copy();
}
public function onSectorClick1Copy() {
$data['ListMenuLevel1'] = $this->Categories_model->listsector1();
$config = array();
$config["base_url"] = base_url() ."index.php/welcome/onSectorClick1Copy";
$total_row = $this->productdisplay_model->subproductlist_count($this->session->userdata('subcategory2_id'));
$config['total_rows'] = $total_row;
$config['per_page'] = 20;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 1;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->load->library('pagination');
$this->pagination->initialize($config);
$page = ($this->uri->segment(3) != '' ? $this->uri->segment(3) : 1);
$offset = (($config['per_page']) * ($page - 1));
$limit = $config['per_page'] * $page ;
$data['sub2products'] = $this->productdisplay_model->sub2Productsmenu($this->session->userdata('subcategory2_id'),$limit, $offset);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ', $str_links);
$this->load->view('subproductlist', $data);
}
模型
public function subproductlist_count($id) {
$this->db->select('*');
$this->db->from('sub2_category');
$this->db->where('sub1_categoryid_fk', $id);
$this->db->order_by("sub2_category.sub1_categoryid_fk ");
$query = $this->db->get();
return $query->num_rows();
}
public function sub2Productsmenu($id,$limit, $offset){
$this->db->select('*');
$this->db->from('sub2_category');
$this->db->where('sub1_categoryid_fk', $id);
$this->db->order_by("sub2_category.sub1_categoryid_fk ");
$this->db->limit($limit, $offset);
return $this->db->get()->result();
}
查看
<div class="center">
<ul class="pagination">
<?php
foreach ($links as $link) {
echo "<li>" . $link . "</li>";
}
?>
</ul>
</div>
答案 0 :(得分:0)
这就是我如何创建分页,它完美无缺。以下是Controller中的代码。
$config['base_url'] = base_url().'property/properties';
$config['total_rows'] = $this->property_model->countProperties();
$config['per_page'] = 6;
//===========================//
// Defining Pagination Styles//
//===========================//
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '<span aria-hidden="true">«</span>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '<span aria-hidden="true">»</span>';
$config['next_tag_open'] = '<li>';
$config['next_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['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = '<<';
$config['last_link'] = '>>';
$this->pagination->initialize($config);
$data['properties']=$this->property_model->getAllProperties($config['per_page'],$offset);
$data['pagination']=$this->pagination->create_links();
在我看来
<!-- Start properties content bottom -->
<?php if(isset($pagination)){?>
<div class="aa-properties-content-bottom">
<nav>
<?php echo $pagination?>
</nav>
</div>
<?php }?>
答案 1 :(得分:0)
试试这个
public function onSectorClick1($offset=0) {
$id = $_GET["id"];
$this->session->set_userdata('subcategory2_id', $_GET['id']);
$this->session->set_userdata('subcategory2_name', $_GET['name']);
$data['ListMenuLevel1'] = $this->Categories_model->listsector1();
$config = array();
$config["base_url"] = base_url() ."index.php/welcome/onSectorClick1";
$total_row = $this->productdisplay_model->subproductlist_count($id);
$config['total_rows'] = $total_row;
$config['per_page'] = 20;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 1;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->load->library('pagination');
$this->pagination->initialize($config);
$data['sub2products'] = $this->productdisplay_model->sub2Productsmenu($id,$limit, $offset);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ', $str_links);
$this->load->view('subproductlist', $data);
}
此代码有一个工作模型here
答案 2 :(得分:0)
In my controller code I just changed the session name as sub2_id and I passed the get variable "$id" to the session.The following change in code is displayed below.
<强>控制器强>
public function onSectorClick1() {
$id = $_GET["id"];
$this->session->set_userdata('sub2_id', $id);
$this->onSectorClick1Copy();
}