PHP Classes

PHP Array Paging: Generate pagination links for listings in an array

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 61%Total: 813 All time: 4,242 This week: 75Up
Version License PHP version Categories
array-paging 1.1.2GNU General Publi...5.3HTML, PHP 5
Description 

Author

This class can generate pagination links for listings in an array.

It takes a list of items to display in an array and generates links to browse the the previous and next pages that will list the items.

The current page number is retrieved from a request parameter. The limit number of items to display per page is configurable.

Picture of rafi randoni
  Performance   Level  
Name: rafi randoni <contact>
Classes: 2 packages by
Country: Indonesia Indonesia
Age: ???
All time rank: 194426 in Indonesia Indonesia
Week rank: 180 Up4 in Indonesia Indonesia Up

Recommendations

MySQL Pagination
Pagination for MySQL queries

Example

<?php
/*
* =============================
* Array Paging |
* -----------------------------
* -----------------------------
* Example
* -----------------------------
* =============================
*/

/*
* Templates Config :
* --------------------------------------------------------------------------
* <ul> :: Full Tag
* <li> :: Num Tag || Disabled Tag || Active Tag
* <a href="">Links</a>
* </li> :: Num Tag Close
* </ul> :: Full Tag Close
*/


/* Include library */
require_once 'ArrayPaging.php';


/* Data for paging */
$data = array(
       
0 => array(
               
'name' => 'A',
               
'address' => 'Address_A',
            ),
       
1 => array(
               
'name' => 'B',
               
'address' => 'Address_B',
            ),
       
2 => array(
               
'name' => 'C',
               
'address' => 'Address_C',
            ),
       
3 => array(
               
'name' => 'D',
               
'address' => 'Address_D',
            ),
    );


/*
* ===============================================
* Examples 1
* ===============================================
*/
/* Simple Paging */
$paging = new Paging($data, array('limit'=>2));
$page = (isset($_GET['page']) ? $_GET['page'] : 1);
$paging->setPage($page);

echo
'<pre>';
var_dump($paging->getData());
echo
$paging->getLinks();


/*
* ===============================================
* Examples 2
* ===============================================
*/
/* Paging With Own Template */
$options = array(
   
'full_tag' => '<div class="paging">',
   
'num_tag' => '<span>',
   
'active_tag' => '<span class="active">',
   
'disabled_tag' => '<span class="disabled">',
   
'limit' => 2,
);
$paging2 = new Paging($data, $options);
$page2 = (isset($_GET['page']) ? $_GET['page'] : 1);
$paging2->setPage($page2);

echo
'<pre>';
var_dump($paging2->getData());
echo
$paging2->getLinks();
?>


  Files folder image Files (2)  
File Role Description
Plain text file ArrayPaging.php Class ArrayPaging Class
Accessible without login Plain text file example.php Example example

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:813
This week:0
All time:4,242
This week:75Up
User Ratings User Comments (1)
 All time
Utility:87%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:-
Examples:87%StarStarStarStarStar
Tests:-
Videos:-
Overall:61%StarStarStarStar
Rank:1074
 
This is a very good and useful class ;-)
9 years ago (José Filipe Lopes Santos)
70%StarStarStarStar