[Pagination] Navigate Entries per page UPDATED
A Simple way to display entries per page with limits to group numbers so they do not get too big and styles for the navigation bar
Live example is here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Numbering Sample</title>
<style>
#numbers {
font:normal 100%/200% Georgia, "Times New Roman", Times, serif;
padding:2px 20px;
clear:both;
text-align:center;
}
#numbers a {
border:1px #0066FF solid;
padding:3px 4px;
margin:2px;
text-decoration:none;
}
#numbers a:hover, #numbers u {
border:1px #0066FF solid;
padding:3px 4px;
margin:2px;
background:#000099;
color:#FFF;
}
</style>
</head>
<body><h1>Example of numbering entries in PHP</h1>
<p>
Please get the code <a href="http://gadelkareem.com/2006/10/14/entries-per-page/">here</a><br />
<?php
#getting Gadelkareem feed as a sample array
$parser = xml_parser_create();
xml_parse_into_struct($parser,file_get_contents('http://gadelkareem.com/feed') , $vals, $index);
xml_parser_free($parser);
$limit = 3; #number of entries per page
$st = 1; #how many number we skip before putting '....';
$max = count($index['TITLE']); #counting the array we're displaying
###here goes the page
$pg = isset($_GET['pg']) ? $_GET['pg'] : 1;
$nlimit= $max > $pg*$limit ? $pg*$limit : $max;
#printing feed
for($i=(($pg-1)*$limit); $i<($nlimit+1);$i++){
echo "<li><a href=\"{$vals[$index['LINK'][$i]]['value']}\">{$vals[$index['TITLE'][$i]]['value']}</a></li>";
}
#the numbers
$nav = '<div id="numbers">';
$tp = ceil($max/$limit);
$st++;
for($x=1; $x<($tp+1); $x++){
if($tp > ($st*2)){
if(($x==$st+1 && $pg > ($st*2))){
$x = $pg-$st;
$nav .= '....';
}elseif($x==($pg+$st) && ($tp-$pg) > ($st*2)){
$x = $tp-$st;
$nav .= '....';
}
}
$nav .= $x==$pg ? "<u>{$x}</u>" :"<a href=\"{$_SERVER['PHP_SELF']}?pg={$x}\" >{$x}</a>";
}
$nav .= '</div>';
echo $nav
?>
</p>
</body>
</html>