title: Pagination on Codeigniter always selected on page 1
body: <p>I've a problem with pagination.
  It show the data on database by its limit,but it always select page 1 even i click the second page.</p>
  
  <p>I'm using sorting and pagination in 1 function
  This is my controller</p>
  
  <pre><code>    function index($sort_by = 'title', $sort_order= 'asc', $offset = 0)
      {
          $limit = 2;
  
          $data['fields'] = array(
              'nama' =&gt; 'Nama',
              'jabatan' =&gt; 'Jabatan',
              'jampulang' =&gt; 'Jam Pulang',
              'alasan' =&gt; 'Alasan',
              'pendingtask' =&gt; 'Pending Task',
              'status' =&gt; 'Status'
          );
  
          $result = $this-&gt;karyawan_pulang-&gt;search($limit,$offset, $sort_by, $sort_order);
  
          $data['pulang'] = $result['rows'];
          $data['num_results'] = $result['num_rows'];
          $data['main_content'] = 'karyawanpulangarea';
  
          // pagination
          $config = array();
          $config['base_url'] = site_url("izinpulang/index/$sort_by/$sort_order");
          $config['total_rows'] = $data['num_results'];
          $config['per_page'] = $limit;
          $config['url_segment'] = 4;
          $config['num_links'] = 3;
          $config['use_page_numbers'] = TRUE; 
          $this-&gt;pagination-&gt;initialize($config);
          $data['pagination'] = $this-&gt;pagination-&gt;create_links();
  
          $data['sort_by'] = $sort_by;
          $data['sort_order'] = $sort_order;
  
          $this-&gt;load-&gt;view('includes/template', $data);
  
      }
  </code></pre>
  
  <p>And this is my model</p>
  
  <pre><code>function search($limit, $offset, $sort_by, $sort_order)
  {
      $sort_order = ($sort_order == 'desc') ? 'desc' : 'asc';
      $sort_columns = array('nama', 'jabatan', 'jampulang', 'alasan', 'pendingtask', 'status');
      $sort_by = (in_array($sort_by, $sort_columns)) ? $sort_by : 'nama';
  
      // result query
      $q = $this-&gt;db-&gt;select('pid, nama, jabatan, jampulang, alasan, pendingtask, status')
          -&gt;from('izin_pulang')
          -&gt;limit($limit, $offset)
          -&gt;order_by($sort_by, $sort_order);
  
      $ret['rows'] = $q-&gt;get()-&gt;result();
  
      // count query
      $q = $this-&gt;db-&gt;select('COUNT(*) as count', FALSE)
          -&gt;from('izin_pulang');
  
      $tmp = $q-&gt;get()-&gt;result();
      $ret['num_rows'] = $tmp[0] -&gt; count;
  
  
      return $ret;
  }
  </code></pre>
  
  <p>This is my view</p>
  
  <pre><code>&lt;h2&gt;&lt;a href="&lt;?php echo base_url();?&gt;site/form_area"&gt;&lt;img src='&lt;?php echo base_url();?&gt;assets/img/backs.png'/&gt;Back&lt;/a&gt;&lt;/h2&gt;
  &lt;h3&gt;
  &lt;?php
  
  if (empty($pulang)) {
  
  echo "There's No Data!";
  
  
  }
  
  else 
  {
  
  ?&gt;
  &lt;/h3&gt;
  &lt;div id="content" class="container_center"&gt;
  &lt;h3&gt; Daftar Karyawan Izin Pulang&lt;/h3&gt;
  &lt;div id="count"&gt;
      Jumlah Data : &lt;?php echo $num_results;?&gt;
  &lt;/div&gt;
  &lt;div class="table"&gt;
  &lt;table&gt;
  &lt;thead&gt;
      &lt;tr align="center"&gt;
          &lt;?php foreach ($fields as $field_name =&gt; $field_display):?&gt;
          &lt;th &lt;?php if($sort_by == $field_name) echo "class=\"sort_$sort_order\""?&gt;&gt;
              &lt;?php echo anchor("izinpulang/index/$field_name/" .
                  (($sort_order == 'asc' &amp;&amp; $sort_by == $field_name) ? 'desc' : 'asc') ,
              $field_display); ?&gt;
          &lt;/th&gt;
          &lt;?php endforeach;?&gt;
          &lt;th&gt;Edit&lt;/th&gt;
          &lt;th&gt;Download&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;?php
  
  foreach ($pulang as $data):
  
  ?&gt;
  &lt;tbody&gt;
      &lt;tr align="center"&gt;
          &lt;?php foreach ($fields as $field_name =&gt; $field_display):?&gt;
          &lt;td&gt;
              &lt;?php echo $data-&gt;$field_name; ?&gt;
          &lt;/td&gt;
          &lt;?php endforeach;?&gt;
           &lt;td&gt; &lt;a href="&lt;?php echo base_url();?&gt;izinpulang/baca/&lt;?php echo $data-&gt;pid; ?&gt; "&gt;&lt;img src='&lt;?php echo base_url();?&gt;assets/img/edit.png'/&gt;&lt;/a&gt;&lt;/td&gt;
           &lt;td&gt; &lt;a href="&lt;?php echo base_url();?&gt;izinpulang/download/&lt;?php echo $data-&gt;pid; ?&gt;"&gt;&lt;img src='&lt;?php echo base_url();?&gt;assets/img/downloads.png'/&gt;&lt;/a&gt; &lt;/td&gt;         
      &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;?php
  
  endforeach;
  
  ?&gt;
  
  &lt;/table&gt;
  &lt;?php if (strlen($pagination)):?&gt;
  &lt;div id="count"&gt;
      Pages : &lt;?php echo $pagination;?&gt;
  &lt;/div&gt;
  &lt;?php endif; ?&gt;
  &lt;/div&gt;
  &lt;?php
  
  }
  ?&gt;
  &lt;br&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I try to change the url_segment just like google and people recommend it.
  But however its still not working. But if i only do some pagination and not do sorting</p>
  
  <pre><code>$config['base_url'] = site_url("izinpulang/index/");
  </code></pre>
  
  <p>The pagination is working but doesn't load the second data on page 2. It show the same data as page 1.</p>
  
  <p>Any advice ? Thank you</p>