Skip to content
Advertisement

How can I use the data table pagination?

Now I’m calling up the whole data and using the data table to express it in a view. However, if there is a lot of data, rendering speed is slow. What should we do to improve?

in this datatable code

JavaScript

in this sql code and table view code

JavaScript

What should I do to pagination using datatable and php and mariadb?

Advertisement

Answer

Make limit of the results like:

JavaScript

That way you will return 100 results per page. The variable $offset_var can be passed through URL like a GET variable (of course prior the SQL query):

JavaScript

And than you can use it for example for hyperlinks for your pagination.

You should of course not forget to sanitize this variable. Something like:

JavaScript

And also think about the eventual case when somebody hits the page with a big offset number in the url (make sure this “empty” page still renders pretty).

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