Giter Club home page Giter Club logo

pagination's Introduction

pagination

Paginate record sets, not tied in directly to a database.

Usage

  1. include the class
  2. instantiate a new object pass in the number of items per page and the instance identifier, this is used for the GET parameter such as ?p=2
  3. pass the set_total method the total number of records
  4. show the records
  5. call the page_links method to create the navigation links
include('paginator.php');

$pages = new Paginator('10','p');
$pages->set_total('100'); //or a number from say a database

//display the records here

echo $pages->page_links();

if using a database you limit the records by placing $pages->get_limit() in your query, this will limit the number of records

select * from table $pages->get_limit()

by default the page_links method created links starting with ? this can be changed by passing in a parameter to the method:

echo $pages->page_links('&');

The method also allows you to pass in extra data such as a series of GET's

echo $pages->page_links('?','&status='.$_GET['status'].'&active='.$_GET['active']);

##Database example

//include the class
include('paginator.php');

//create new object pass in number of pages and identifier
$pages = new Paginator('10','p');

//get number of total records
$rows = $db->query('SELECT id FROM table');
$total = count($rows);

//pass number of records to
$pages->set_total($total); 

$data = $db->query('SELECT * FROM table '.$pages->get_limit());
foreach($data as $row) {
    //display the records here
}

//create the page links
echo $pages->page_links();

##MVC example

using this class in an MVC environment its almost the same, only the database or dataset calls come from the model instead of the page directly.

in the controller:

//create a new object
$pages = new Paginator('10','p');

//set the total records, calling a method to get the number of records from a model
$pages->set_total( $this->_model->get_all_count() );

//calling a method to get the records with the limit set
$data['records'] = $this->_model->get_all( $pages->get_limit() );

//create the nav menu
$data['page_links'] = $pages->page_links();

//then pass this to the view, may be different depending on the system
$this->_view->render('index', $data);

pagination's People

Watchers

James Cloos avatar NT Pte Ltd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.