<?php
//generate array
$myResults = range(0, 710);
$resultsPerPage = 30; //30 results on a page
$totalPages = ceil(count($myResults)/$resultsPerPage); //calculate total number of pages
echo "total pages = " . $totalPages . "<br />";
$page = $_GET['p']; //get page number
echo "page number = " . $page . "<br /><br />";
//display results
$sliceStart = ($page-1)*$resultsPerPage;
$slice = $resultsPerPage;
echo "<pre>";
print_r(array_slice($myResults, $sliceStart, $slice));
echo "</pre>";
include("pageNumbers.class.php");
//parameters: $page = current page number
//$totalPages = total number of pages
//3 = numbers to display on the left and right of the current page number
$pag = new pageNumbers($page, $totalPages, 5);
//the first and the last page number will always be displayed
//we need a separator between the first/last page number and the middle page numbers
$separator = "...";
foreach($pag->numbers as $pageNumber=>$type)
{
//each number has a type
//there are 4 types:
// "current" - the curent page number;
// "link" - link to other page numbers
// "separatorAfter" - first line number when it needs the separator (separator after number)
// "separatorBefore" - last line number when it needs the separator (separator before number)
switch($type)
{
case "current": echo ' ' . $pageNumber . ' ';
break;
case "link": echo ' <a href="index.php?p=' . $pageNumber . '">' . $pageNumber . '</a> ';
break;
case "separatorAfter": echo ' <a href="index.php?p=' . $pageNumber . '">' . $pageNumber . '</a> ' . $separator . ' ';
break;
case "separatorBefore": echo ' ' . $separator . ' <a href="index.php?p=' . $pageNumber . '">' . $pageNumber . '</a>';
break;
}
}
?>
|