Pagination is essentially the process of taking a set of results and spreading
them out over pages to make them easier to view.

Its always possible that your SQL SELECT statement query may result into thousand of records. But its is not good idea to display all the results on one page.
So we can divide this result into many pages as per requirement.

Paging means showing your query result in multiple pages instead of just put them all in one long page.

MySQL helps to generate paging by using LIMIT clause which will take two arguments. First argument as OFFSET and second argument how many records should be returned
from the database.

Below is a simple example to fetch records using LIMIT clause to generate paging.

There are three files index.php, funcion.php and database file.

config.php //start here

//php code start here

define (“DB_HOST”, “localhost”); // Your database host name
define (“DB_USER”, “root”); // Your database user
define (“DB_PASS”,””); // Your database password
define (“DB_NAME”,””); // Your database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(“Couldn’t make connection.”);
$db = mysql_select_db(DB_NAME, $link) or die(“Couldn’t select database”);

//config.php end here

index.php //start here

//php start here
include_once “dbConfig.php”;
$i = 1;
$start = 0;
$limit = 50;

$page = $_GET[‘id’];
if (!$page)$page = 0;
else $page–; //first page become 0 instead of 1
$serial = ($page * $limit) + 1;
if (isset($_GET[‘id’])) {
$id = $_GET[‘id’];
$start = ($id – 1) * $limit;
}

// Your SQL query go here. This query will display all record by setting the Limit.

$sql = “SELECT * FROM TABLE_NAME where status = 1 LIMIT “.$pageLimit.” , “.$setLimit;
$query = mysql_query($sql);

while ($rec = mysql_fetch_array($query)) {
//php end here

}
//close div here
//php start here
//Pagination start here.

$rows = mysql_num_rows(mysql_query(“SELECT * FROM TABLE_NAME where status = 1 “));
$setLastpage = ceil($total/$per_page);
$total = ceil($rows / $limit);
//php end here

//php start here
if ($id > 1) {
echo ““;
}
if ($id != $total) {
echo ““;
}

echo “

    “;
    for ($i = 1; $i <= $total; $i++) { if ($i == $id) { echo "
  • ” . $i . “
  • “;
    } else {
    echo “

  • ” . $i . “
  • “;
    }
    }
    echo “

“;

}
//php end here

// css is here
//start of style
.pagination-holder {
width: 100%;
display: inline-block;
}
.pagination-holder .prev, .pagination-holder .next {
float: left;
margin: 0;
padding: 6px 15px;
background: #0a508e;
color: #fff;
margin-right: 5px;
font-size: 12px;
border-radius: 0px;
}
.pagination-holder .prev:hover, .pagination-holder .next:hover {
background: #ff6702;
transition: ease-in-out 0.3s;
}
.pagination-holder .page {
float: right;
margin: 0;
padding: 0;
}
.pagination-holder .page li {
list-style: none;
display: inline-block;
}
.pagination-holder .page li a, .pagination-holder .current {
display: block;
padding: 6px 10px;
background: #fff;
border: 1px solid #ccc;
border-collapse: collapse;
text-decoration: none;
color: #848484;
border-left: 0px;
}
.pagination-holder .page li a:hover {
background: #f5f5f5;
}
.pagination-holder .page li:first-child a {
border-left: 1px solid #ccc;
border-radius: 3px 0px 0px 3px;
}
.pagination-holder .page li:last-child a {
border-radius: 0px 3px 3px 0px;
}
.pagination-holder .page .current {
color: #fff;
background: #337ab7;
cursor: default;
border-color: #337ab7;
}
//end of style

41 Comments
  1. Amazing! Its actually awesome article, I have got much clear idea on the topic of from this article.

  2. Oh my goodness! an amazing article dude. Thank you However I am experiencing issue with ur rss . Don?t know why Unable to subscribe to it. Is there anyone getting identical rss problem? Anyone who knows kindly respond. Thnkx

  3. I am often to blogging and i really appreciate your content. The article has really peaks my interest. I am going to bookmark your site and keep checking for new information.

  4. After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think.

  5. You made some decent points there. I looked on the internet for the issue and found most individuals will go along with with your website.

  6. I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

  7. Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.

  8. There is noticeably a bundle to know about this. I assume you made certain nice points in features also.

  9. It?s hard to find knowledgeable people on this topic, but you sound like you know what you?re talking about! Thanks

  10. I’m often to running a blog and i actually appreciate your content. The article has really peaks my interest. I am going to bookmark your website and keep checking for brand new information.
    check out my website http://www.granice.pl/post,zakupy-przez-internet,20,442

  11. you will have a great weblog here! would you prefer to make some invite posts on my weblog?
    check out my website http://www.forum-filmowe.pl/topics4/3145.htm?start=50

  12. There is noticeably a bundle to find out about this. I assume you made certain good points in options also.
    best affordable destination weddings http://rafaelebxsn.thezenweb.com/How-Much-You-Need-To-Expect-You-ll-Pay-For-A-Good-Caribbean-Weddings-8126797

  13. Aw, this was a really nice post. In thought I would like to put in writing like this additionally – taking time and actual effort to make an excellent article… however what can I say… I procrastinate alot and in no way appear to get something done.

  14. Hello! I just wish to give a huge thumbs up for the great information you may have right here on this post. I will be coming again to your weblog for more soon.

  15. Best prices.[url=http://wmplati.com/itm/grand-theft-auto-v-gta-5-pc-onlajn-garantija/1847398]Buy GTA 5[/url] – http://wmplati.com

  16. Best prices.[url=http://wmplati.com/itm/grand-theft-auto-v-gta-5-pc-onlajn-garantija/1847398]Buy GTA 5[/url] – http://wmplati.com Minecraft, Uplay, Steam, Origin.

  17. Spot on with this write-up, I really assume this web site needs far more consideration. I’ll most likely be once more to learn way more, thanks for that info.

  18. A powerful share, I just given this onto a colleague who was doing slightly analysis on this. And he in actual fact purchased me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to debate this, I feel strongly about it and love reading more on this topic. If potential, as you change into expertise, would you mind updating your weblog with more details? It is extremely useful for me. Big thumb up for this blog publish!

  19. I discovered your weblog site on google and check a couple of of your early posts. Proceed to keep up the excellent operate. I simply further up your RSS feed to my MSN Information Reader. Searching for forward to reading extra from you later on!…

  20. It’s arduous to find knowledgeable individuals on this subject, however you sound like you already know what you’re speaking about! Thanks

  21. you might have an awesome blog here! would you wish to make some invite posts on my blog?

  22. You made some first rate points there. I looked on the internet for the difficulty and found most individuals will associate with together with your website.

  23. Youre so cool! I dont suppose Ive learn anything like this before. So good to seek out any person with some authentic thoughts on this subject. realy thanks for beginning this up. this website is one thing that is needed on the net, someone with a little originality. useful job for bringing something new to the internet!

  24. It is also important that the technicians continually improve their skills. The essential oil is then massaged gently about the scalp.Ask for a few customer references from the company you are evaluating. However, you need to ensure that you choose efficiency over price. Professional in 3D design skills with vector based<br>5. Deciding Upon Trouble Free Strategies In Antivirus Software Package System 2013Article From Article Directory DatabaseA Instruction To Immediate Secrets Of Antivirus World wide web Safety 2018Maloof Coy   Submitted 2014 06 05 08:35:20 Sad to say, with automatic electronic mail extractor device, the undertaking can be carried out inside of seconds or minimal probable period. Their review are valuable since they have experienced the work themselves. Borrow libIn Need Of A Good Garage Door Contractor Fast? Fasten Your SeatbeltsIn Need Of A Good Garage Door Contractor Fast? Fasten Your SeatbeltsAugust 1, 2013 | Author: Jeff Peterson | Posted in BusinessIt would be a fantasy if the perfect garage door repair contractor just showed up at your door for Christmas, but that isn’t going to happen anytime soon. They don??t know how lucky they are, nor do they realize how arrogant are their views. [url=http://www.cheapjerseyswholesalejerseys.us.com/]Wholesale Jerseys China[/url]. It is also important that the technicians continually improve their skills. Employees and customers are much more likely to have great ideas about possible improvements to a company as they are on the shop floor, so to speak, and know what works and what does not. Later,[url=http://www.cheapjerseyswholesalejerseys.us.com/]Wholesale NFL Jerseys Free Shipping[/url],[url=http://www.cheapjerseyswholesalejerseys.us.com/]Cheap Jerseys Shop[/url], in blind tests with different types of pollen, the same students all again reacted strongly to the bottlebrush pollen.Visit my site??http://www.cheapjerseyswholesalejerseys.us.com/

  25. If you find ʏourself enthusiastiϲ about a new profession ɑs
    a paralegal, tthere are a number of choices which you can consider.
    Υou may determine that being a contract paгаlegɑⅼ is
    the way in which tnat you wish to pursue tһis field.
    You possibly can start bү weighing the pros and cons of this thrilling new approaⅽh of working within the paralegal discipline; and
    yoᥙ could decide that its thee most suіtablе choice for you.

  26. Настройка xRumer 16 при первом запуске. Видеоурок №1: https://youtu.be/LFngR0NqvTE

  27. I used to be more than happy to search out this web-site.I wanted to thanks to your time for this glorious read!! I positively enjoying every little little bit of it and I have you bookmarked to take a look at new stuff you blog post.

  28. After study a couple of of the weblog posts in your web site now, and I truly like your manner of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls try my website online as properly and let me know what you think.

  29. Post writing is also a fun, if you be acquainted with after that you can write if not it is complex to write.

  30. Hiya! I simply wish to give an enormous thumbs up for the good info you’ve gotten right here on this post. I might be coming back to your blog for more soon.

  31. Hi there! I just would like to give a huge thumbs up for the good information you will have right here on this post. I might be coming back to your weblog for extra soon.

  32. Hi there, You have done a fantastic job. I will definitely digg
    it and personally suggest to my friends.

    I’m sure they’ll be benefited from this site.

  33. The subsequent time I read a blog, I hope that it doesnt disappoint me as a lot as this one. I imply, I know it was my option to learn, however I actually thought youd have something interesting to say. All I hear is a bunch of whining about one thing that you could repair for those who werent too busy searching for attention.

  34. Another option to have a secure home is to change your lock rather
    than install a new. 1940 Tigertail Blvd, Unit 2 Fort Lauderdale, FL 33004.

    Only the pins and tumblers of the locks are replaced,
    thereby invalidating existing keys.

  35. There is noticeably a bundle to know about this. I assume you made sure nice points in features also.

  36. You made some respectable factors there. I regarded on the internet for the difficulty and located most people will go together with together with your website.

  37. Youre so cool! I dont suppose Ive read something like this before. So nice to seek out someone with some unique thoughts on this subject. realy thank you for beginning this up. this website is one thing that’s needed on the internet, somebody with a bit of originality. useful job for bringing something new to the internet!

  38. Would you be enthusiastic about exchanging hyperlinks?

  39. Your house is valueble for me. Thanks!…

  40. An impressive share, I just given this onto a colleague who was doing a little bit analysis on this. And he in actual fact purchased me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If possible, as you turn into expertise, would you mind updating your blog with more details? It is extremely helpful for me. Huge thumb up for this blog submit!

Leave a Reply

Your email address will not be published. Required fields are marked *