thinkphp5简单的分页

admin3年前thinkphp900
//获取相关文章
    public function getSearchArticle() {
        if(iS_AJAX) {
            $typeid = input('id/d', 0);
            if(empty($typeid)) $this->error('Typeid error');
            $keyword = input('keyword/s', '');
            if(empty($keyword)) $this->error('Keyword error');
            $where['a.title'] = ['like', "%$keyword%"];
            $where['a.typeid'] = $typeid;
            $where['a.arcrank'] = 0;
            $where['a.is_del'] = 0;
            $pagesize  = 8;
            $page = input('p/d', 1);
            $counts = M('archives')->alias('a')->where($where)->count();
            if($counts > 0) {
                $pages = ceil($counts/$pagesize);
                if($page > $pages) $page = $pages;
                $begin = ($page - 1) * $pagesize;
                $res = M('archives')->alias('a')->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')->where($where)->field('a.aid,a.title,a.add_time,b.dirname')->limit($begin, $pagesize)->select();
                $output = '<ul class="newslist" style="padding: 0;">';
                foreach($res as &$v) {
                    $output .= '<li class="transition"><a href="/'.$v['dirname'].'/'.$v['aid'].'.html" title="'.$v['title'].'" target="_blank" class="od a">'.$v['title'].'<span class="addtime">'.date('Y-m-d', $v['add_time']).'</span></a></li>';
                }
                $output .= '</ul>';
                if($pages > 1) {
                    $output .= '<div class="pages">';
                    if($page == 1) {
                        $output .= '<a href="javascript:;">上一页</a>';
                    }else {
                        $prevPage = $page - 1;
                        $output .= '<a href="javascript:;" onclick="ajaxGetSearchArticle('.$typeid.', \''.$keyword.'\', '.$prevPage.')">上一页</a>';
                    }
                    for($i=1; $i <= $pages; $i++) {
                        if($i == $page) {
                            $output .= '<span class="red">'.$i.'</span>';
                        }else {
                            $output .= '<span style="cursor: pointer;" onclick="ajaxGetSearchArticle('.$typeid.', \''.$keyword.'\', '.$i.')">'.$i.'</span>';
                        }
                    }
                    if($page == $pages) {
                        $output .= '<a href="javascript:;">下一页</a>';
                    }else {
                        $nextPage = $page + 1;
                        $output .= '<a href="javascript:;" onclick="ajaxGetSearchArticle('.$typeid.', \''.$keyword.'\', '.$nextPage.')">下一页</a>';
                    }
                    $output .= '</div>';
                }
               
               
                $this->success($output);
            }else {
                $this->error('No record');
            }
        }
    }


相关文章

thinkphp5 缓存 cache

http://www.17bigdata.com/book/thinkphp5/ZaXiang/HuanCun.html...

tp导出excel信息

public function studentsExport(){        set_time_limit (0);     ...

thinkphp图片等比例缩小

$image = \think\Image::open($filename);        // 返回图片的宽度      &n...

thinkphp 项目报错No input file specified.

1提示:“No input file specified.”原因在于使用的PHP5.6是fast_cgi模式,而在某些情况下,不能正确识别path_info所造成的错误。默认的.htaccess里面的...

如何查看thinkphp当前版本号

如何查看thinkphp当前版本号

这篇文章主要介绍了如何查看thinkphp当前版本号,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。查看当前thinkphp版本有两种方...

thinkphp分页,数字页+上下页+跳转+每页数据下拉

<?php namespace Think; class Page{     public $firstRow;&...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。