ページング

<style>
 .current{
	font-weight: bold;
 }
</style>
<?php
$limit = 10;
$page = empty($_GET&#91;"page"&#93;)? 1:$_GET&#91;"page"&#93;;
$disp=3;

$next = $page+1;
$prev = $page-1;

$start = ($page-floor($disp / 2) > 0) ? ($page-floor($disp/2)) : 1;
$end = ($start > 1) ? ($page+floor($disp/2)) : $disp; //55
$start = ($limit < $end) ? $start-($end-$limit):$start;

if($page != 1 ) {
         print '<a href="?page='.$prev.'">&laquo; 前へ</a>';
 }

if(($page - $disp) > 0 | $page == $disp){
	if($start >= floor($disp/2)){
        print '<a href="?page=1">1</a>';
        if($start > floor($disp/2) and $page != $disp){
        	print "..."; 
        }
        if($page == $disp){
        	print " ";
        } 
  }
}
for($i=$start; $i <= $end ; $i++){
        $class = ($page == $i) ? ' class="current"':"";
        if($i <= $limit && $i > 0 )
            print '<a href="?page='.$i.'"'.$class.'>'.$i.'</a> ';
    }

if($limit > $end){
	if($limit - 1 > $end) print "...";
	print '<a href="?page='.$limit.'">'.$limit.'</a>';
}
if($page < $limit){
        print '<a href="?page='.$next.'">次へ &raquo;</a>';
}

?>