程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> thinkphp實現分頁

thinkphp實現分頁

編輯:關於PHP編程

thinkphp實現分頁


public function alist()
{
    $this->validateLogin();
    $this->createurl();
    $article = M('article');
    $page = I('get.page');
    $perpage = 20;
    $page = (isset($page) && ($page>0)) ? $page : 1;//current page
    $last = $page - 1;
    $next = $page + 1;
    $url =  "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?page=";
    $sum = count($article->where("is_delete=0")->select());
    $pages = ceil($sum/$perpage);
    $this->assign('sum',$sum);
    $this->assign('pages' ,$pages);
    if ($page > 1) {
        $arr = "<a href='" . $url  . "1''>首頁</a>";
        $arr .= "<a href='" . $url . $last . "''>上一頁</a>";
    } else {
        $arr = "<a href='javascript:void(0)' class='noallow'>首頁</a>";
        $arr .= "<a href='javascript:void(0)' class='noallow'>上一頁</a>";
    }

    if ( ($page-2)>0 ) {
        $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ($page-2) . "</a>";
        $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ($page-1) . "</a>";
    } else if( (($page-2)<=0) && (($page-1)>0) ) {
        $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ($page-1) . "</a>";
    }

    $arr .= "<a href='" . $url . $last . "'' class=\"number current\">" . ($page) . "</a>";

    if ( ($page+1)<=$pages ) {
        $arr .= "<a href='" . $url . $next . "'' class=\"number\">" . ($page+1) . "</a>";
       if ( ($page+2)<=$pages ) {
           $arr .= "<a href='" . $url . $next . "'' class=\"number\">" . ($page+2) . "</a>";
       }
    }
    if ($page < $pages) {
        $arr .= "<a href='" . $url . $next . "''>下一頁</a>";
        $arr .= "<a href='" . $url . $pages . "''>尾頁</a>";
    } else {
        $arr .= "<a href='javascript:void(0)' class='noallow'>下一頁</a>";
        $arr .= "<a href='javascript:void(0)' class='noallow'>尾頁</a>";
    }
    $this->assign('page',$arr);
    $data = $article->where("is_delete=0")->page($page,$perpage)->select();
    $this->assign('article',$data);
    $this->display();
}

 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved