CodeIgniter Forums
Pagination with $_GET => double page variables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Pagination with $_GET => double page variables (/thread-47628.html)



Pagination with $_GET => double page variables - El Forum - 12-15-2011

[eluser]teomor[/eluser]
I'm using the $_GET version of the pagination. This is my config:
Code:
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'offset';
and this is my controller:
Code:
$this->pagination->base_url = site_url()."admin/users/?".http_build_query($_GET);
$this->pagination->total_rows = $total_rows; // total rows from the db
$this->data['pages'] = $this->pagination->create_links(); // this is the html output
Now, when I change to another page, the previous value of offset is stuck in the URL, but the new offset variable appears also, like this: admin/users/?offset=&offset=5. I looked at the Pagination class and there's actually no attempt to remove the existing variable so... you tell me, is this a bug?


Pagination with $_GET => double page variables - El Forum - 02-28-2012

[eluser]ballmatic[/eluser]
I had the same problem as you. After some digging around on PHP.net, I came across the following which works wonders:

Code:
http_build_query( Array( 'offset' => null ) + $this->input->get(NULL, TRUE) )

Basically, you use the first Array to NULL out any values you want. You used the variable "offset", so I used that in this example.