Skip to content
Advertisement

How to make search results and pagination not disappear on click to next page?

whenever i click next page, my search results disappear and my pagination disappear as well. I want them both to stay whenever i click the page numbers, for example when i click next page, the table data displays straight away. right now i have to search the keyword again to display the page 2 results. Is there a fix to this? i cant seem to figure it out what’s wrong with my code. thanks for any help in advance.

JavaScript

Advertisement

Answer

Maybe it could be helped by saving all the stuff you want to keep into a Cookie(s)

JavaScript

Name: It is used to set the name of the cookie. Value: It is used to set the value of the cookie. Expire: It is used to set the expiry timestamp of the cookie after which the cookie can’t be accessed. Path: It is used to specify the path on the server for which the cookie will be available. Domain: It is used to specify the domain for which the cookie is available. Security: It is used to indicate that the cookie should be sent only if a secure HTTPS connection exists.

For reading from the cookie:

JavaScript

In your case, I would start with

JavaScript

We have three different points of look

  1. Asking the DB for each page (it may lags the server)
  2. Loading everything into cookies, doing the user save all this data (Deppends on user network speed and storage size )
  3. Loading everything once, and by JS, show/hide the pages you want or not to show (Requires more RAM from the user)

Edit 1:

PHP

JavaScript

Warning

Please, note that if the cookie expires, and the user wants to load the next page, it will cause an error for do not have the cookie setted, so it’s better to check it when the next page load (probably on paginate() function) and handle that error.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement