thinkphp实现分页_PHP教程

WBOY
Lepaskan: 2016-07-12 09:03:30
asal
1085 orang telah melayarinya

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();
}
Salin selepas log masuk

 


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)) ?...
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan