September 10, 2013 4:44 pm

How to create pagination in PHP and MySQL with AJAX

I have wrote an article on pagination with a simple class and many users like it and download it so now i have decided to write its and updated version with AJAX. In this article i am going to explain you how to create pagination in PHP & MySQL with AJAX for your websites. Pagination is a very important part in your websites reporting and this article will help you to create it very very simple.


Also Read: How to create Advance Pagination in PHP & MySQL with jQuery

Database design and table:

database name => phpgang
table name => pagination
column names => id, post, postlink


Database file run in your mysql to create database and add data in table.


Database configuration file edit database name, user and password as per your configuration.


Use Css for style.


Pagination Logic function Include in your file.


Index file contain pages logic.



This file load data from database on auto load and onclick events.

Please Download the code and use this script feel free to comment if face any issue in it we love to reply on your comments. 🙂

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • realy nice working. gr8

    • huzoorbux

      Thanks @disqus_rpTWcTWu3u:disqus.

  • farmanullah memon

    good job

    • huzoorbux

      Thanks @8752ed99c04ea7bcd05381e5850dd9f1:disqus

  • Ruby James

    Nice Article sir

  • Susang

    i can’t get access to the db and it comes with “Access denied for user ”@’localhost’ to database ‘phpgang'”. have set a password to the database

    • Susang

      got it right by setting the conf to root. no problem!

  • Luca Pandolfo

    If I have a lot of pages…can I hide with “…” like the image of this article? Can you explain me how I can do this? Thx

  • Mahmudur Rahman

    Why you need the downloader to be a subscriber ?

    • huzoorbux

      Its websites requirement so you have to subscribe.

  • Amr Dam

    how i can download demo

  • dskanth

    Thanks for this simple yet powerful explanation of using jquery ajax with php 🙂

  • Army

    Thank you I want to download source code

  • Army

    How i can download code ?

  • Danish

    Hi.. My question is same as Luca Pandolfo. I want “…” between numbers as shown in tutorial image. i try to edit function.php but don’t get it. how to get this thing?

  • nguyen thinh


  • Unais Ellias

    How i can download code ?

    • Unais Illias

      How i can download code ?

  • Bakhtiyor

    I subscribed, but I can`t download. Error: “Sorry no email found subscribe below”

  • Mark

    In the demo I see 24 links and that is all. So where is the prev nex button?

  • amin rohmatullah

    Thanks for this great code. By the way, I have one table with two columns, each column has its own content, and I want both of them paginated independently, Where and how should i modify the code ?

  • Penelope

    I subscribed, confirmed, but cannot download still. It says that there is no E-Mail address under that name.

    • Atanu


  • rajendher

    dear admin,
    which displays all the page numbers. but we need first 1,2,3 …..8,9,10 last like . what should we do now.
    please reply……… appriciated more ……….

    • huzoorbux

      Use our Latest Tutorial on Pagination with ……. How to create Advance Pagination in PHP & MySQL with jQuery Latest Article.

      • rajendher

        yeah i have seen just now. but i am getting following error message in “loadData.php” why ?
        The page cannot be displayed because an internal server error has occurred.
        there is no error in database connection but not getting please help sir…………

  • An article has been very successful in

  • im


  • Oeurn Sophearith

    Dear phpgang!
    Why i can’t do. it is no result at all.
    and when i click download this script it is error and can not download it.
    please….. send it for me please….

  • hossein

    this article is very good…
    please send for me tanks

  • dtr


  • Ashiq

    how to display all months from create date to end date in archives…
    ex: august 2014(2)
    july 2014(0)
    march 2014(2)

  • Ali Rizk


  • Ankur

    great tutorial,was searching for the same from a long time.

  • สุกนกานต์

    thank you for script

  • Jerry

    I have no idea what I am doing wrong, but I could not get this to work. The best it would do is display the pagination but no data from the database. It gave no errors.

    • Elyor M

      same to me

  • Jerry

    I have no idea what I am doing wrong, but I could not get this to work. The best it would do is display the pagination but no data from the database. It gave no errors.

  • Tharun

    How to do column level search using ajax.. can u please make on tutorial ?..

  • Atul pradhan

    actually m getting problem that, its displaying first page but when i click second page showing nothing and repeating my div blank on the same page. and not going back too.

  • Paritus Jaimun


  • Shuttheup Eiei

    Thank you

  • ปอ ยังซิง


  • Thank you