Solace Solace - 12 days ago 6
HTML Question

How do I display database rows on multiple pages with Ajax?

I have a database with a table having a big number of rows. I am fetching the data in this table and displaying it in an HTML table on a web page.

My requirement is to display 20 records initially and then when the user clicks a button labelled

Next
, I show the next 20 records and so on...

So I have initially fetched first 20 rows from the table in my PHP (server-side), and then assigned a JS function to the
onclick
attribute of the
button
labelled
Next
. Inside this JS function, I use an AJAX call which brings me the next 20 rows. Then within this JS function, I replace the HTML rows with these new rows.

I need something like this:

enter image description here

The question is that are there any plugins available which can implement that functionality for me? If a plugin is available, implementing it manually wouldn't make sense because being a rookie, I can't develop it better than the developers of that plugin.

Answer

Yes

This is called pagination - a quick search for "ajax pagination mysql php" or similar brings up a wide range of options. I can't recommend any particular one as your question is too broad; I can only reasonably go as far as a definition.

Internally they use the MySQL LIMIT keyword which may help give further things to search for or experiment with depending on your actual use case.