douzhi2988 2017-03-11 07:15
浏览 47
已采纳

分页'上一个'链接在codeigniter中不起作用

This is my pagination code.When I click 'next' button it displaying the next page with remaining product images,but if I click 'previous' its showing the empty page.The same code I applied for another page pagination its working fine but its not working for this page.

Controller

     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'] = '&nbsp;<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('&nbsp;', $str_links);
            $this->load->view('subproductlist', $data);
        }

Model

     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();


        }

View

     <div class="center">
                <ul class="pagination">
                     <?php
                    foreach ($links as $link) {
                        echo "<li>" . $link . "</li>";
                    }
                    ?>
                </ul>
            </div>
  • 写回答

3条回答 默认 最新

  • douman9420 2017-03-14 10:25
    关注
    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.
    

    Controller

     public function onSectorClick1() {
    
            $id = $_GET["id"];
    
            $this->session->set_userdata('sub2_id',  $id);
    
            $this->onSectorClick1Copy();
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?