<?php
function navigatie($currentpage,$totalpages,$url)
{
$output = '';
$output_num = '';
// both = 4 of meer
if (($currentpage - 4) > 0 && ($currentpage + 4) < $totalpages) {
for($a = ($currentpage-4);$a <= ($currentpage+4);$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
if (($currentpage - 4) == 1) {
$first = false;
} else {
$first = true;
}
if (($currentpage + 4) == $totalpages) {
$last = false;
} else {
$last = true;
}
// left = 4 of meer
} elseif (($currentpage - 4) > 0) {
$math = $totalpages - $currentpage;
$start_temp = 9 - $math;
$start = $currentpage - $start_temp;
if ($start < 1) {
$start = 1;
}
for($a = $start;$a <= $totalpages;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = false;
$first = true;
// right = 4 of meer
} elseif (($currentpage + 4) < $totalpages) {
if ($totalpages > 9) {
$loop = 9;
} else {
$loop = $totalpages;
}
for($a = 1;$a <= $loop;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = true;
$first = false;
// none = 4 of meer
} else {
for($a = 1;$a <= $totalpages;$a++) {
if ($a == $currentpage) {
$output_num .= ' <b>[' . $a .']</b> ';
} else {
$output_num .= ' <a href="' . $url . $a . '">' . $a . '</a> ';
}
}
$last = false;
$first = false;
}
if ($first == true) {
$output .= ' <b><a href="' . $url . '1">[eerste]</a></b> ';
}
if ($currentpage != 1) {
$output .= ' <b><a href="' . $url . ($currentpage-1) .' ">[vorige]</a></b> ';
}
$output .= " " . $output_num . " ";
if ($currentpage != $totalpages) {
$output .= ' <b><a href="' . $url . ($currentpage+1) . ' ">[volgende]</a></b> ';
}
if ($last == true) {
$output .= '<b><a href="' . $url . $totalpages . ' ">[laatste]</a></b> ';
}
return $output;
}
$itemsperpage = 30;
$totalrecords = 1000; // dit kan een aantal records zijn uit de database
$totalpages = ceil($totalrecords/$itemsperpage); if (!IsSet($_GET['p'])) { $currentpage = 1;
} else {
$currentpage = ceil($_GET['p']); }
if ($currentpage < 1 || $currentpage > ceil($totalpages)) { $output = 'Helaas, deze pagina bestaat niet.';
} else {
$output = navigatie($currentpage,$totalpages,'?p=');
$output .= '<br /><br />Pagina: ' . $currentpage;
}
?>
<!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>
<title>Navigatie</title>
<style type="text/css">
* {
font-family : verdana, tahoma, sans-serif;
font-size : 12px;
}
body {
background-color : #fff;
margin : 10px;
padding : 0px;
}
</style>
</head>
<body>
<?php
?>
</body>
</html>