Query string paging with codeigniter

Asked

Viewed 74 times

1

How do I search with pagination using query string in Codeigniter? I’m trying to search in the documentation but couldn’t find it! I have following scenario:

http://localhost/meusite/procurar/s?search_state=RJ&search_city=Rio+de+Janeiro

If it was on a page without search it would be easy, just indicate the main page that will be displayed the listing, but as a search system as I do for when clicking on the next page keep the search criteria in get?

  • Although it is in English, it is an interesting example that can help you: https://stackoverflow.com/questions/40542031/how-to-make-pagination-query-string-in-codeigniter

  • @Ricardopunctual has no problem being in another language, but there is only one query string, in my case there are two, not to mention that later will come the pagination! The bigger problem is that Uri->segment only identifies up to’S' and completely ignores the rest, so I can’t pass all the link to the $config['base_url array']

  • Thanks @Ricardopunctual for the willingness to help, I edited the post the way I could solve, I don’t know if it was the best way, but solved for me, thanks again!

  • 1

    @Thimoreira, you can answer your own question :). Put the solution as an answer and approve it. Then you can remove the "ANSWERED" from the title of your question and preferably remove the solution from your question. This way it is more organized. Get it? And welcome to Sopt!

  • 1

    Sorry @Dherik for making the edit wrong, I’m new here and I haven’t adapted yet! Thanks for the advice!

  • @Thimoreira, that this, just arrived, normal make some mistakes :). Sopt thanks the edition! rs. By the way, you can accept your answer by clicking on the Checkmark button

Show 1 more comment

1 answer

1

RESOLVED AS FOLLOWS:

As the problem was to identify what would be the number of the pagination, so I did it this way, I do not know if it is the best, but it worked for me:

     $state   = $this->input->get('search_state');
     $city    = $this->input->get('search_city');

     $urlExp  =  explode("=", $_SERVER['QUERY_STRING'] );

     $maximum                   = 1;
     $start                     = isset( $urlExp[3] ) ? $urlExp[3] : 0;

     $config['base_url']        = base_url( 'procurar/result?search_state=' .$state. '&search_city=' .$city. '' );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.