当前位置:首页 > 新闻中心 >

thinkphp实现分页

编辑:北京飞炫空间展览展示有限公司 时间:2017-09-09 10:21:08阅读次数:2
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 = "" . $_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(); }

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:武汉网页设计 https://www.feimao666.com

上一篇:VB.NET利用正则表达式巧妙限制字符输入 下一篇:最后一页

相关阅读