Welcome Guest, Not a member yet? Register   Sign In
Pagination Problem with Search Results

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?

Messages In This Thread
Pagination Problem with Search Results - by El Forum - 12-07-2009, 05:50 AM
Pagination Problem with Search Results - by El Forum - 12-07-2009, 05:56 AM

Theme © iAndrew 2016 - Forum software by © MyBB