title: CodeIgniter pagination with order by and search
body: <p>How can I make the pagination not reset the sorting from page 1? Because when I order the table, it will be reset on the next page. How can I fix it?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public function viewstudents(){
          $this-&gt;pagination('students');
  
          $studedit = $this-&gt;session-&gt;userdata('studedit_id');
          if(isset($studedit)){
              $this-&gt;session-&gt;unset_userdata('studedit_id');
          }
  
          $id = $this-&gt;session-&gt;userdata('id');
  
          $userdata['user'] = $this-&gt;UsersModel-&gt;select_admin($id);
          $this-&gt;load-&gt;view('include/header_admin', $userdata);
  
          $data['students'] = $this-&gt;UsersModel-&gt;getStudents(10, $this-&gt;uri-&gt;segment(3));
          $data['page'] = $this-&gt;uri-&gt;segment(3);
  
          $msg = $this-&gt;session-&gt;userdata('msg');
          if(isset($msg)){
              $data['msg'] = $msg;
          }
  
          $this-&gt;load-&gt;view('admin/view_students', $data);
          $this-&gt;load-&gt;view('include/footer_admin');
      }
  </code></pre>
  
  <p>And the pagination function:</p>
  
  <pre><code>public function pagination($table) {
              $this-&gt;load-&gt;library('pagination');
  
              $config['base_url'] = base_url().'admin/view'.$table;
              $config['per_page'] = 10;
              $config['num_links'] = 3;
              $config['total_rows'] = $this-&gt;db-&gt;get($table)-&gt;num_rows();
              $config['full_tag_open'] = '&lt;ul class="pagination"&gt;';
              $config['full_tag_close'] = '&lt;/ul&gt;';
              $config['first_link'] = '&lt;span aria-hidden="true"&gt;&amp;larr;&lt;/span&gt; First';
              $config['last_link'] = 'Last &lt;span aria-hidden="true"&gt;&amp;rarr;&lt;/span&gt;';
              $config['first_tag_open'] = '&lt;li&gt;';
              $config['first_tag_close'] = '&lt;/li&gt;';
              $config['prev_link'] = '&amp;laquo';
              $config['prev_tag_open'] = '&lt;li class="prev"&gt;';
              $config['prev_tag_close'] = '&lt;/li&gt;';
              $config['next_link'] = '&amp;raquo';
              $config['next_tag_open'] = '&lt;li&gt;';
              $config['next_tag_close'] = '&lt;/li&gt;';
              $config['last_tag_open'] = '&lt;li&gt;';
              $config['last_tag_close'] = '&lt;/li&gt;';
              $config['cur_tag_open'] = '&lt;li class="active"&gt;&lt;a href="#"&gt;';
              $config['cur_tag_close'] = '&lt;/a&gt;&lt;/li&gt;';
              $config['num_tag_open'] = '&lt;li&gt;';
              $config['num_tag_close'] = '&lt;/li&gt;';
  
              $this-&gt;pagination-&gt;initialize($config);
      }
  </code></pre>
  
  <p>I believe it's in the <code>$config['base_url']</code> so I tried changing it to </p>
  
  <p><code>$config['base_url'] = base_url().'admin/view'.$table.'?sortby='.$sort.'&amp;direction='.$dir;</code> </p>
  
  <p>but still, the pagination doesn't set in the next page.</p>