Im trying to paginate results returned by DB. But when I try to get the offset from URI:
questions/search?content=foobar/4
/4 should be the offset but it is assigned to the $_GET value.
This is the whole method in the controller:
$results = $this->question->search_results_count($content);
$this->load->library('pagination');
$config['total_rows'] = count($results);
$offset = $this->uri->segment(3);
if ($offset == false) $offset = 0;
$config['full_tag_open'] = '<ul class="pages">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li><a class="active">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '<li>';
$config['next_tag_open'] = '<li class="next">';
$config['next_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_link'] = '<<';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = '>>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['per_page'] = 1;
$config['uri_segment'] = 2;
$config['page_query_string'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['suffix'] = '?content='.$content;
$config['base_url'] = base_url().'questions/search/';
$this->pagination->initialize($config);
As I’m sure you know, URIs don’t work like that. The query string must be at the end (or before a
#hash fragment). This query string:Means
$_GET['content'] = 'foobar/4';You need to change your pagination URLs to something like this:
The
/after the 4 there is also optional.You’ll have to remove the query string from your pagination’s
$config['base_url']and instead append it to the links in the view, which sadly involves hacking the pagination class…Or try this undocumented feature:
Or better yet, just add
$config['suffix'] = '{YOUR QUERY STRING}';to your config before loading the class. This should automatically add the query string to every link’shref.Some adjustments to your config area also needed: