+ 3

What should I use to do pagination on a webpage?

I am building a website project from scratch. I am using Smarty, PHP and SQLite3. Currently the page lets the user search the database and returns results. I am limiting the result set size at the moment using LIMIT in the SQL query. Now I want to be able to add pagination to the result list and remove the limit from the query. Years ago, I would have used PHP to do the pagination but nowadays surely there is something else I can use so the page doesn't have to reload? I have looked into React and I'm sure JS would let me do it but I'm rather inexperienced in both. I'm looking for simplicity mostly. An easy way to add this functionality. Is it possible to have PHP request an entire result set from the database, then use JS to handle the pagination? I'm also open to using a "load 50 more results" at the bottom of the list as well if that would be easier.

15th Jan 2021, 11:03 PM
Nathan Stanley
Nathan Stanley - avatar
2 Respostas
+ 1
If the table data is not too large, you can try to api to get all the table data into an array, then use JavaScript to slice the array into page data. Here the example of getting global array into table with pagination https://code.sololearn.com/Wg9sM5pwglIq/?ref=app
21st Aug 2021, 4:22 AM
Calviղ
Calviղ - avatar
0
One of variants is create an API for your App. On the server side you should create some methods that will be calculate count of all pages and also the callback method that will be give an answer in JSON format (current page, count of all pages for example). Then, when you send a query from your client side, server will give the JSON data that you will be parse. After that you can work with it and create pagination.
18th Jan 2021, 7:25 AM
Максим
Максим - avatar