Hi.
In a blog I must implement a paging system
a little different.
It's a navigation system
rather than a really paging system.
This is the first draft :
<?php
//With this query SELECT post_ID FROM posts ORDER BY post_ID DESC;
// I retrieve an array like this
session_start();
if(!isset($_SESSION['paging_by_id'])){
$_SESSION['paging_by_id']= array('15','14','13','12','11','10');
}
function increment($n){
return ++$n;
}
function decrement($n){
return --$n;
}
function pagingById($array,$value){
if(in_array($value,$array)){
$tmp= array_flip($array);
$current= $tmp[$value];
$previous= increment($tmp[$value]);
$next= decrement($tmp[$value]);
//It's the first therefore the last post
if($current===0){
echo '<a href="'.$_SERVER['PHP_SELF'].'?p='.$array[$previous].'">Previous</a>';
}
//It's the last therefore the first post
elseif((count($array)-2)==$next){
echo '<a href="'.$_SERVER['PHP_SELF'].'?p='.$array[$next].'">Next</a>';
}
else{
echo '<a href="'.$_SERVER['PHP_SELF'].'?p='.$array[$previous].'">Previous</a>';
echo " ";
echo '<a href="'.$_SERVER['PHP_SELF'].'?p='.$array[$next].'">Next</a>';
}
}
}
if(isset($_GET['p'])){
echo pagingById($_SESSION['paging_by_id'],$_GET['p']);
}
else{
echo '<a href="'.$_SERVER['PHP_SELF'].'?p=15">Start</a>';
}
?>
What do you think about ?