这是我的分页代码。它在第一页显示20个图像,而不是第二页的移动链接。我的分页代码不起作用。请您查看我的代码并给我你的建议,谢谢。
控制器
public function onSectorClick() {
$id = $_GET["id"];
$this->session->set_userdata('sub1category_id', $_GET['id']);
$this->session->set_userdata('sub1category_name', $_GET['name']);
$this->onSectorClickCopy();
}
public function onSectorClickCopy(){
$this->load->helper('url');
$data['ListMenuLevel1'] = $this->Categories_model->listsector1();
$config = array();
$config["base_url"] = base_url() . "index.php/welcome/onSectorClickCopy?id=".$this->session->userdata('sub1category_id')."&name=".$this->session->userdata('sub1category_name');
$total_row = $this->productdisplay_model->record_count($this->session->userdata('sub1category_id'));
$config['total_rows'] = $total_row;
$config['per_page'] = 20;
//$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
//$config['page_query_string'] = TRUE;
//$config['reuse_query_string'] = FALSE;
$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);
/* if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
} */
$page = ($this->uri->segment(3) != '' ? $this->uri->segment(3) : 1);
//$offset = $config['per_page']*$page;
$offset = (($config['per_page']) * ($page - 1)) + 1;
$limit = $config['per_page'] * $page;
$data['sub1products'] = $this->productdisplay_model->sub1Productsmenu($this->session->userdata('sub1category_id'),$limit, $offset);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ', $str_links);
$this->load->view('productlist', $data);
}
}
模型
<?php
class productdisplay_model extends CI_Model {
function __construct() {
parent::__construct();
}
public function record_count($id) {
$this->db->select('*');
$this->db->from('sub1_category');
$this->db->where('main_categoryid_fk', $id);
$this->db->order_by("sub1_category.main_categoryid_fk ");
$query = $this->db->get();
return $query->num_rows();
}
public function sub1Productsmenu($id,$limit, $offset){
$this->db->select('*');
$this->db->from('sub1_category');
$this->db->where('main_categoryid_fk', $id);
$this->db->order_by("sub1_category.main_categoryid_fk ");
$this->db->limit($limit, $offset);
return $this->db->get()->result();
}
public function sub1Productfetch($id) {
$query = $this->db->select('product_image,sub1_category_name,product_description');
$this->db->from('sub3_category');
$this->db->join('sub2_category', 'sub3_category.sub2_categoryid_fk=sub2_category.id', 'left');
$this->db->join('sub1_category', 'sub2_category.sub1_categoryid_fk=sub1_category.id', 'left');
//$this->db->join('maincategory', 'sub1_category.main_categoryid_fk=maincategory.id', 'left');
$this->db->where('sub1_category.id',$id);
//$this->db->order_by('rand()');
$this->db->limit(1);
return $this->db->get()->result();
}
}
查看
<div class="center">
<ul class="pagination">
<?php
foreach ($links as $link) {
echo "<li>" . $link . "</li>";
}
?>
</ul>
</div>
答案 0 :(得分:0)
这使您可以从URI字符串中检索信息
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
请考虑此示例http://www.domainname.com/index.php/blog/language/php/function
它会返回
$this->uri->segment(1); // blog
$this->uri->segment(2); // language
$this->uri->segment(3); // php
$this->uri->segment(4); // function
根据您的网址:http://localhost/terasukhintrade/index.php/welcome/onSectorClickCopy?id=1&name=agriculture/2
$ this-&gt; uri-&gt; segment(3)得到? //尝试自己调试
但在你的情况下,谁必须获取最后一个uri段。
替代1
$last = end($this->uri->segments);
//Where, segments is a class variable.
替代2
$last = end($this->uri->segment_array());
替代3
$total = $this->uri->total_segments();
$last = $this->uri->segment($total);
将$page = ($this->uri->segment(3) != '' ? $this->uri->segment(3) : 1);
更新为($this->uri->segment($total) != '' ? $this->uri->segment($total) : 1); // as per alternative 3