title: Codeigniter pagination error after searching
body: <p>After searching data when i click on next page then it doesn't work with searching results. After click it goes on first page. How can i solve this problem ?
  Thank you </p>
  
  <p>Controller: </p>
  
  <pre><code> public function gkclientsadd(){
      $arg["src"] = 0;
      $arg["pageOffset"] = 0;
      $np = $this-&gt;uri-&gt;segment(3);
      $data["offset"] = 0;
      $this-&gt;search_by = 0;
  
      if($_SERVER['REQUEST_METHOD'] == 'GET')
      {
          if(isset($_GET["client_search"]))
          {
              $arg["login"] = $this-&gt;input-&gt;get('login');
              $arg["pwd"] = $this-&gt;input-&gt;get('pwd');
              $arg["basetariff"] = $this-&gt;input-&gt;get("basetariff");
              $arg["crc"] = $this-&gt;input-&gt;get("crc");
              $arg["resone"] = $this-&gt;input-&gt;get("resone");
              $arg["rpp"] = $this-&gt;default_rpp;
              $arg["offset"] = $this-&gt;default_offset;
              $arg["src"] = 1;
  
              $this-&gt;search_basetariff = $arg["basetariff"];
              $this-&gt;search_currency = $arg["crc"];
              $this-&gt;search_parent = $arg["resone"];
              $this-&gt;search_by = 1;
              //print_r($arg);die;
          } else $arg["src"] = 0;
      }
      if(!empty($np)){
              $arg["pageOffset"] = ($np/$this-&gt;default_rpp);
              $arg["rpp"] = $this-&gt;default_rpp;
              $arg["offset"] = ($this-&gt;default_rpp)*$arg["pageOffset"];
              $data["offset"] = $arg["offset"];
              $arg["src"] = 1;
      }
  
      $data["gkclientsData"] = $this-&gt;admin_model-&gt;getGkclients($this-&gt;userId, $this-&gt;rtc_table,$arg, $this-&gt;default_rpp, $this-&gt;default_offset); 
      $data["getTotalGk"] = $this-&gt;admin_model-&gt;getTotalGk($this-&gt;rtc_table,$arg);
      $data["totalRecords"] = count($data["getTotalGk"]);
      $data["totalPage"] = $data["totalRecords"]/$this-&gt;default_rpp;
      $data["Page"] = $arg["pageOffset"]+1;
  
      $config = array();
      $config["base_url"] = base_url() . "index.php/admin/gkclientsadd";
      $config["total_rows"] = $data["totalRecords"] ;
      $config["per_page"] = $this-&gt;default_rpp;
      $config["uri_segment"] = 3;
      $config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
      $this-&gt;pagination-&gt;initialize($config);
      $page = ($this-&gt;uri-&gt;segment(3)) ? $this-&gt;uri-&gt;segment(3) : 0;
      $data["links"] = $this-&gt;pagination-&gt;create_links(); 
  
      $this-&gt;load-&gt;view('admin/clients/gkclientsadd',$data);
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public function getGkclients($userId, $rtc_table,$arg, $default_rpp,$default_offset)  
  {
      $this-&gt;load-&gt;database();
      if($arg['src']== 1){
          $whr = "";
          $rpp = "";
          $offset = "";
      if(!empty($arg["rpp"])) $rpp .= " LIMIT ".$arg["rpp"]."";
      if(!empty($arg["offset"])) $offset .= " OFFSET ".$arg["offset"]."";
  
      if(!empty($arg["login"])) $whr .= " AND $rtc_table.login = '".$arg["login"]."'";
      if(!empty($arg["pwd"])) $whr .= " AND $rtc_table.password = '".$arg["pwd"]."'";
      if(!empty($arg["basetariff"])) $whr .= " AND $rtc_table.id_tariff = '".$arg["basetariff"]."'";
      if(!empty($arg["crc"])) $whr .= " AND $rtc_table.id_currency = '".$arg["crc"]."'";
      if(!empty($arg["resone"])) $whr .= " AND $rtc_table.id_res = '".$arg["resone"]."'";
  
      } else {
          $whr="";
          $rpp= "Limit $default_rpp"; 
          $offset= "OFFSET $default_offset"; 
      }
  
      $query = "SELECT DISTINCT $rtc_table.id_client,$rtc_table.id_res,$rtc_table.login,$rtc_table.password,$rtc_table.id_tariff,
                  $rtc_table.account_state,$rtc_table.type,$rtc_table.type2,currency_names.name
                          FROM $rtc_table, currency_names
                              WHERE currency_names.id = $rtc_table.id_currency $whr
                                  order by $rtc_table.login ASC $rpp $offset"; 
  
      $query_result = $this-&gt;db-&gt;query($query);
      $gkData=$query_result-&gt;result();
  
      return $gkData;
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/yMa6d.jpg" rel="nofollow">http://i.stack.imgur.com/yMa6d.jpg</a></p>