Web coding support
  • Home
  • PHP
  • Phonegap
  • Angular Js
  • Node Js
  • Previous year questions
  • B.Tech Questions
  • RTU

How to create pagination in PHP and MySQL

  • By admin
  • Jun-26-2016
  • MySQL, oops, Pagination, PHP
  • 0 Comments.

To handle the large number of records in database pagination is most important part to view records.

This article will teach you how to create pagination in PHP with mysql database results.

I have created a pagination class which holds the mysql results and html for generated links.
This is very simple and secure to use.

Follow these steps to set pagination with your DB results.
1. Download a fresh copy of pagination class from github.

2. Extract the zip and put Pagination folder in your project directory.

3. Include the autoload file in your file

require_once __DIR__."/Pagination/autoload.php";

Now the pagination class is fully access in your project.
4. Now first create an object of pagination class and pass the limit for display the no of result on a page.

$pagination = new \Pagination\Pagination(10);

Here 10 is the limit of per page results.
Pagination class has been initialized.
5. To get results from database call `sql()` and put your sql query without limit.

$pagination->sql("SELECT * FROM dummy");
        $pagination->results();

6. And in last for generate pagination links call –

$pagination->links();

There are so many other functions for different links;

echo "Start: ".$pagination->start();
    echo "End : ".$pagination->end();
    echo "CurrentPage : ".$pagination->currentPage();
    echo "Current Page  URL: ".$pagination->url();
    echo "Total Page: ".$pagination->totalPage;
    echo "Total Result: ".$pagination->total();

Download from git
Demo

Here an example

Related Posts

  • What is static functions in phpWhat is static functions in php
  • Magic function library for Codeigniter like CakePHPMagic function library for Codeigniter like CakePHP
  • How to manage multi level categories in PHP and MySQLHow to manage multi level categories in PHP and MySQL
  • How to handle duplicate data in MySqlHow to handle duplicate data in MySql
  • What is a difference between a method and a function?What is a difference between a method and a function?
  • Fetch random results form MySQLFetch random results form MySQL

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • Click to print (Opens in new window)

Related

FacebookTwitterGoogle+Google GmailPrintPinterestFacebook MessengerWordPressShare

Comments

Leave a Reply Cancel reply

← Previous Post Next Post →

Categories

  • Angular Js
  • Array
  • Codeigniter
  • facebook
  • Javascript
  • jquery
  • MySQL
  • oops
  • Pagination
  • Phonegap
  • PHP

Recent Posts

  • Fetch random results form MySQL
  • HTML DOM Manipulation using JavaScript
  • Magic function library for Codeigniter like CakePHP
  • What is the difference between an interface and abstract class
  • How to reset an array keys in php

Tags

Abstract Class angularjs array codeigniter facebook facebook login facebook sdk form validations function hide html Interface javascript jquery magic functions method mysql ng-hide ng-show nghide ngshow oops pagiation php recursion reference show static static functions

Subscribe us

Name
Email *
About This Site

We provide the simplest tutorials for web development.

Pages
  • Home
  • B.Tech Questions
  • Previous year questions
  • RTU
Categories
  • Angular Js
  • Array
  • Codeigniter
  • facebook
  • Javascript
  • jquery
  • MySQL
  • oops
  • Pagination
  • Phonegap
  • PHP
Search
  • facebook
  • twitter

Powered by Minmarks.com  |  A Coding blog by By Jitendra.

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.