我的分页代码不起作用

This is my pagination code.It displaying 20 images in first page and its not moving link to second page.My pagination code is not working.Could you please go through my code and give me your suggestions,Thank you.

Controller

                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'] = '&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);
                        /* 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('&nbsp;', $str_links);

                        $this->load->view('productlist', $data);                           
                    }
                }

Model

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

View

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

This provides you to retrieve information from your URI strings

$this->uri->segment(n); // n=1 for controller, n=2 for method, etc

consider this example http://www.domainname.com/index.php/blog/language/php/function

it will return

$this->uri->segment(1); // blog
$this->uri->segment(2); // language
$this->uri->segment(3); // php
$this->uri->segment(4); // function

According to your url : http://localhost/terasukhintrade/index.php/welcome/onSectorClickCopy?id=1&name=agriculture/2

$this->uri->segment(3) gets? // try to debug yourself

But in your case, who have to fetch the last uri segment.

Alternate 1

$last = end($this->uri->segments); 
//Where, segments is a class variable.

Alternate 2

$last = end($this->uri->segment_array());

Alternate 3

$total = $this->uri->total_segments();
$last = $this->uri->segment($total);

Update $page = ($this->uri->segment(3) != '' ? $this->uri->segment(3) : 1); to ($this->uri->segment($total) != '' ? $this->uri->segment($total) : 1); // as per alternative 3