thinkphp3.2 分页方法和模板

//实例化
            $serve = M('spreadinfo');
            //获取总数量
            $count = $serve->count();
            //获取每页显示数量
            $pagesize = I('page','','intval')?I('page','','intval'):10;
            //获取总页数
            $pages = ceil($count/$pagesize);

            //获取当前页码
            $current_page = I('p','','intval')?I('p','','intval'):1;

            if($current_page < 0){
                $current_page = 1;
            }

            if($current_page > $pages){
                $current_page = $pages;
            }

            $cu_page = $current_page - 1;

            $list = $serve->field(true)->limit($cu_page*$pagesize,$pagesize)->select();


            $this->assign('select', $list); // 赋值数据集
            $this->assign('current_page', $current_page);
            $this->assign('pages', $pages);

            $this->assign('pagesize', $pagesize);


<td colspan="8" bgcolor="#FFFFFF">
            <div class="pages">
                    每页显示<a href="{:U('Admin/serve?page=10')}"><button>10</button></a>
                    <a href="{:U('Admin/serve?page=20')}"><button>20</button></a>
                    &nbsp;&nbsp;|&nbsp;&nbsp;
                    <a href="{:U('Admin/serve',array('p'=>1,'page'=>$pagesize))}"><button>首页</button></a>&nbsp;
                    <a href="{:U('Admin/serve',array('p'=>$current_page-1,'page'=>$pagesize))}"><button>上一页</button></a>
                    {$current_page}/{$pages}
                    <a href="{:U('Admin/serve',array('p'=>$current_page+1,'page'=>$pagesize))}"><button>下一页</button></a>
                    到
                    <form action="{:U('Admin/serve')}" style="display:inline-block;">
                        <input type="hidden" name="page" value="{$pagesize}">
                        <input type="text" name="p" id="page" style="width:50px;">页
                    &nbsp;
                        <button>go</button>
                        </form>  
            </div>
            </td>

你可能感兴趣的:(thinkphp3.2 分页方法和模板)