Search code examples
phpmysqllinuxnginxlamp

Making forward/backward Buttons in html for Table Data


I have more than 200 data on this table based on HTML and MySQL database:

enter image description here

So, I would like to limit the number of entries shown to 15 and then have next and back button for every 15 other entries.

I am pretty new of LAMP environment, what would be the easiest way to do so?


Solution

  • You can achieve this using LIMIT in MySQL query:

    SELECT * FROM <tbl_name> LIMIT 0,15; # Retrieve first 15 rows
    

    The first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

    You can use generic query like:

    SELECT * FROM <tbl_name> LIMIT (page_no - 1) * items_per_page, items_per_page;
    

    Where page_no will be initialized to 1 and items_per_page will be set to 15 in your case and on Clicking Next you should increment page_no and call the above query (decrement for Previous button)