CodeIgniter Forums
Pagination Problem with Search Results - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Pagination Problem with Search Results (/thread-25285.html)

Pagination Problem with Search Results - El Forum - 12-07-2009

I am trying to create pagination for when a user searches for a term through an input field and options from a drop down list.

In order to preserve what the user has requested when going from one page to another I decided to append the search terms to the url in this format:


The form posts to a function which redirects to the correct url as follows:

function alias_search() {
        redirect('/search/index/'.$this->input->post('search').'/'.$this->input->post('searchType').'/0/', 'location', 301);

Then I have my index function doing the pagination and retrieving of records:

function index() {
        $data['title'] = 'search results';
        //pagination config
        $config['base_url'] = base_url().'index.php/search/index/'.$this->uri->segment(3).'/'.$this->uri->segment(4);
        $config['per_page'] = 2;
        $config['num_links'] = 10;
        $config['full_tag_open'] = '<div class="pagination">';
        $config['full_tag_close'] = '</div>';
        $data['searchType'] = $this->uri->segment(4);
        $searchType = $data['searchType'];
        $config['total_rows'] = $this->ModelName->search_events_rows();

        $data['queryevents'] = $this->ModelName->search_events();
        $data['main_content'] = 'search_view';
        $this->load->view('includes/template', $data);

The $this->ModelName->search_events_rows() function returns the number of rows from the database and $this->ModelName->search_events() gets all the records.

The search_events() function:

function search_events()
        $todays_date = date("Y-m-d H:i:s");
        $config['per_page'] = 2;

        $this->db->select('*')->from('events')->like('title', $this->uri->segment(3))->limit($config['per_page'], $this->uri->segment(5));
        $query = $this->db->get();
        return $query;

The pagination links are also displaying fine in my view using
&lt;?php echo $this->pagination->create_links(); ?&gt;

Clicking on the second page link goes to the correct url but still shows the first page of results and the first link in the pagination is still showing as the current page.

Any ideas as to why this happening?

Pagination Problem with Search Results - El Forum - 12-07-2009

Think I've managed to fix this using

$config['uri_segment'] = 5;