Sayantan Das Sayantan Das - 3 months ago 33
PHP Question

Codeigniter search with pagination is not working

I am trying to implement search with pagination in codeigniter. The problem I am facing is this: The default url for the searched term looks like this

http://guardintel.dev/companies/staff/staff_search?name=riaz&address=&email=
.

But as soon as i select the second page of the link the url changes to

http://guardintel.dev/companies/staff/staff_search/1


so I am losing the search parameters and the page basically list all the results from the database.

My base URL is like this
$config['base_url'] = base_url() . '/companies/staff/staff_search';


I have changed the base url to this according to this post (I've hard coded the url to check)

$config['base_url'] = base_url('/companies/staff/staff_search') . "?company_staff_id=&name=r&address=&email=" ;


As a result the url becomes like this

http://guardintel.dev/companies/staff/staff_search?company_staff_id=&name=r&address=&email=/1


Which searches for an email
/1
. Any suggestion will be appriciated

Answer

In this case you can use page query string:

    $config['base_url'] = base_url('/companies/staff/staff_search') . "?company_staff_id=&name=r&address=&email=" 
    $config['enable_query_strings'] = true;
    $config['page_query_string'] = TRUE;

So you will have &page=1 in your $_GET parameters for next page.

The URL address should be:

http://guardintel.dev/companies/staff/staff_search?company_staff_id=&name=r&address=&email=&page=1

This may help you to fix the problem.