Home >Backend Development >PHP Tutorial >thinkphp implements paging_PHP tutorial

thinkphp implements paging_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:03:301139browse

thinkphp implements paging

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 implements paging public function alist(){ $this-validateLogin(); $this-createurl(); $ article = M(article); $page = I(get.page); $perpage = 20; $page = (isset($page) ($page0)) ?...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn