Creat a Pagination In PHP

How to creat  Pagination in PHP?

As a web programming,  we have some  records need to display page by page, we often need to make a pagination in PHP.

Some PHP paginationc scriptpts listed on the site. Let’s say for instance you have a list of employees in your database, and you want to be able to list them on your web page. If you only have a dozen or so employees, it’s no big deal to just make a simple loop and display them all on the same page, right? Well what happens when you have 50 employees? 100? 1,000? Suddenly listing all of them on the same page doesn’t sound so hot.

Pulling out all that data at the same time can leave your user tapping his fingers on the desk wondering what the frak is taking so long, and when he finally does get his info, it’s a whole frakking novel on one page! Can you imagine going down to the bookstore and picking up a book and instead of the story being divided up by pages, it’s all on one really long page? I heard a rumor they used to do that back in the ancient days. I think they were called scrolls or something, I dunno.

Well anyways, it makes way more sense to break up your list into page-sized chunks, and only query your database one chunk at a time. This drastically reduces server processing time and page load time, as well as gives your user smaller pieces of info to digest, so he doesn’t choke on whatever crap you’re trying to feed him. The act of doing this is called pagination.

A basic pagination routine seems long and scary at first, but once you close your eyes, take a deep breath, and look at each piece of the script individually, you will find it’s actually pretty easy stuff. In fact, in my experience over the years of helping out on the forums, peoples’ hardest problem about pagination is figuring out what it’s called in the first place! But since we’ve got that part sorted out, the rest should be a piece of cake, right? :)

First things first, you need a table with some data in your database to work with. Now I’m not going to go into the details of how to setup a database or how to make a table etc.. if you are really at that point of things, then this tutorial isn’t really for you. It really doesn’t matter what kind of data you have, so if you have an existing table full of info you want to use, you can just plug and chug your table/column info into the script. But for the purposes of this tutorial I will use a table called ‘numbers’ and it will have two columns one called ‘number’ type int and the other one called ‘id’ type int, auto-incremented.

Processing your request, Please wait....