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 mysql , 用自己创建的本地主机和用户名 登录不上
  • ¥15 关于#web项目#的问题,请各位专家解答!
  • ¥15 vmtools环境不正常
  • ¥15 请问如何在Ubuntu系统中安装使用microsoft R open?
  • ¥15 jupyter notebook
  • ¥30 informer时间序列预测
  • ¥20 SSR引物多态性分析
  • ¥15 大漠插件在Win11易语言注册调用和免注册灵异事件,VS上注册调用完全没问题
  • ¥15 Addressable缓存机制做热更新的问题
  • ¥15 微信开发者工具vant组件