Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/array.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mark Rolich  >  Generic Pager  >  examples/array.php  >  Download  
File: examples/array.php
Role: Example script
Content type: text/plain
Description: Example of array pagination
Class: Generic Pager
Browse listings of entries split in multiple pages
Author: By
Last change:
Date: 2012-02-28 00:13
Size: 1,000 bytes
 

Contents

Class file image Download
<?php
include '../Pager.php';
include 
'array.data.php';

$totalCount count($data);
$itemsPerPage 12;
$currentPage = (isset($_GET['p']) && $_GET['p'] != '') ? (int)$_GET['p'] : 1;

$pager = new Pager($totalCount$currentPage$itemsPerPage10);

$offset $pager->getOffset();

if (
$offset != -1) {
    
$pageData array_slice($data$offset$itemsPerPage);
} else {
    
$pageData = array();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Pager - Array example</title>
    <link rel="stylesheet" type="text/css" href="example.css">
</head>
<body>
<?php if (!empty($pageData)) { ?>

<table class="data">
<?php foreach ($pageData as $data) { ?>
<tr><td><?php echo implode('</td><td>'$data); ?></td></tr>
<?php ?>
</table>

<?php } else { ?>
<div>No records found</div>
<?php ?>

<?php echo $pager?>
</body>
</html>