首页 >后端开发 >php教程 >thinkphp实现分页_PHP教程

thinkphp实现分页_PHP教程

WBOY
WBOY原创
2016-07-12 09:03:301113浏览

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