카테고리 없음

page.php 샘플

권성재 2007. 7. 20. 11:37
<?
class pageset{
    var $page; //현재 페이지
    var $total; //총 글수
    var $scale; //한페이지당 글수
    var $pagescale; // [1],[2],[3] 등으로 보일 페이지수
    var $etc; //기타 Query String
    var $totalpage; //총 페이지
    var $startid; // 첫 시작글의 번호
    var $curr_pagescale; // totalpage   를  pagescale 로 나눈값

    function pageset($total,$scale,$pagescale,$page,$etc=''){
        $this->page = $page;
        $this->total = $total;
        $this->scale = $scale;
        $this->pagescale = $pagescale;
        $this->totalpage = ceil($total/$scale);
        $this->startid = ( $page - 1 ) * $scale + 1;
        $this->curr_pagescale = ceil($page/$pagescale);
        $this->etc = $etc;

    }
    function getpage(){

        if ( $this->page <= $this->pagescale ){
            $startpage = 1;
            $endpage = $this->pagescale;
        }else if ( $this->page > $this->pagescale){
            $startpage =  ($this->curr_pagescale  - 1 ) * $this->pagescale + 1 ;
            $endpage =  ( $this->curr_pagescale )  * $this->pagescale ;
        }
        if ( $this->totalpage< $endpage ) $endpage = $this->totalpage;

        // <<  이전 페이지그룹으로 가기
        if ( $this->curr_pagescale > 1 ){
            $prevpage = $startpage - 1;
            $ret .= "<a href='$PHP_SELF?page=$prevpage'> << </a>";
        }

        for($i=$startpage;$i<=$endpage;$i++){
            if ( $i == $this->page )
              $ret .= " <b>$i</b> ";
            else
              $ret .= " <a href='$PHP_SELF?page=$i'>[$i]</a> ";
        }
        // >>  다음 페이지그룹으로 가기
        if ( $this->totalpage > $endpage ){
            $nextpage = $endpage + 1;
            $ret .= "<a href='$PHP_SELF?page=$nextpage'> >> </a>";
        }

        $sss = "<a href='$PHP_SELF?page=1'> 始 </a> &nbsp; ";
        $eee = " &nbsp; <a href='$PHP_SELF?page=$this->totalpage'> 終 </a>";

        return $sss . $ret . $eee;
    }
}

?>