<?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, $itemsPerPage, 10, $options = array(
'first' => false,
'prev' => true,
'next' => true,
'last' => false,
'prevLabel' => '◄',
'nextLabel' => '►'
));
$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 - Customized navigation 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 { ?>
<p>No records found</p>
<?php } ?>
<?php
$navData = $pager->getNavigation();
$result = '<ul class="pager custom">';
foreach ($navData as $link) {
$result .= '<li>
<a href="?p=' . $link['page'] . '" class="' . $link['class'] . '">'
. $link['label']
. '</a></li>';
}
$result .= '</ul>';
echo $result;
$low = $offset + 1;
if ($currentPage >= $pager->pages) {
$high = $pager->total;
} else {
$high = $offset + $itemsPerPage;
}
if ($offset != -1) {
?>
<p>Displaying <?php echo $low; ?> - <?php echo $high; ?> of <?php echo $pager->total; ?></p>
<?php } ?>
</body>
</html>
|