title: Codeigniter pagination using query strings
body: <p>I am trying to implement Codeigniter pagination using query strings but have run into a few issues with this. I've switched on </p>
  
  <pre><code>$config['page_query_string'] = TRUE;
  </code></pre>
  
  <p>So to use query strings for pagination but as far as I can see this is really intended to work when you are using query strings for controller and method routing.  However in my case I am still using URI segments for routing but just want to use query strings for pagination, filtering results, search etc. When I try to use http_build_query() to reconstruct the url with the query string sent through it causes the per_page (which I have renamed to offset) to get written twice on any pagination link after the first page.  The reason being that when I recreate the query string offset is already in the $_GET on subsequent pages and CI is also appending it as well causing it to appear twice.  In the code below I've removed the original per_page query string from the $_GET so the query string can be rebuilt without it and CI will add this during the pagination create_links().  I wanted to check if this makes sense or if there is a cleaner way of dealing with this.</p>
  
  <pre><code>// load pagination library
  $this-&gt;load-&gt;library('pagination');
  
  // set pagination base url
  $config['base_url'] = base_url('accounting/bank/reconcile-account1/account/' . $bank_account_id) . '/?';
  
  // assign current $_GET parameters to local variable as we need to remove offset each time we rebuild query
  // string otherwise it gets appended twice to url
  $get = $_GET;
  
  // unset the offset array item
  unset($get['offset']);
  
  // build first url link
  $config['first_url'] = base_url('accounting/bank/reconcile-account1/account/' . $bank_account_id) . '/?' . http_build_query($get);
  
  // if $get contains items then build these back onto the url
  if (count($get) &gt; 0) $config['suffix'] = '&amp;' . http_build_query($get);
  
  // set the total number of rows
  $config['total_rows'] = $result['total_num_txns'];
  
  // set the number of items per page
  $config['per_page'] = $filter-&gt;limit;
  
  // initialise the pagination config
  $this-&gt;pagination-&gt;initialize($config);
  </code></pre>