ページングに合わせたコンテンツ表示

<style>
 .current{
	font-weight: bold;
 }
</style>
<?php

$logdata = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
$count = count($logdata);
$max = 5;
$limit = ceil($count/$max);

$page = empty($_GET&#91;"page"&#93;)? 1: $_GET&#91;"page"&#93;;

$pstart = ($page == 1)? 0: ($page-1)* $max;
$pend = ($page * $max);


print"<p>";

for($i=$pstart;$i<$pend;$i++){
	if($i >= $count){break;}

	print $logdata[$i]." ";
}

print "</p>";

$page = empty($_GET["page"])? 1:$_GET["page"];
$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>';
}
?>

想像してたより、早かった。