首頁 >後端開發 >php教程 >thinkphp实现分页_PHP教程

thinkphp实现分页_PHP教程

WBOY
WBOY原創
2016-07-12 09:03:301115瀏覽

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=&#39;" . $url  . "1&#39;&#39;>首页</a>";
        $arr .= "<a href=&#39;" . $url . $last . "&#39;&#39;>上一页</a>";
    } else {
        $arr = "<a href=&#39;javascript:void(0)&#39; class=&#39;noallow&#39;>首页</a>";
        $arr .= "<a href=&#39;javascript:void(0)&#39; class=&#39;noallow&#39;>上一页</a>";
    }

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

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

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

 


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1079751.htmlTechArticlethinkphp实现分页 public function alist(){ $this-validateLogin(); $this-createurl(); $article = M(article); $page = I(get.page); $perpage = 20; $page = (isset($page) ($page0)) ?...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn