PHP代码:
<?php namespace HomeController; use ThinkController; use HomeClasCate; class IndexController extends Controller { public function index(){ $where=I('get.');//得到传递的参数数组,没有为空,搜索全部,有的话按条件搜索 $count=M('user')->where($where)->count(); $pagecount=10; $page=new ThinkPage($count,$pagecount); $page->setConfig('first','首页'); $page->setConfig('prev','上一页'); $page->setConfig('next','下一页'); $page->lastSuffix=false;//不加此代码,尾页不显示 $page->setConfig('last','尾页'); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)'); $res=M('user')->where($where)->limit($page->firstRow.','.$page->listRows)->select(); $show=$page->show(); $this->assign('res',$res); $this->assign('page',$show); $this->display(); } }
HTML代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .pagelist{ text-align:center; background:#f1f1f1; padding:7px 0; } .pagelist a{ text-decoration: none; margin:0 5px; border:#6185a2 solid 1px; display:inline-block; padding:2px 6px 1px; line-height:16px; background:#fff; color:#6185a2; } /*点击页码之后改变此点击页码的字体颜色和背景色,span为分页类内部的标签*/ .pagelist span{ margin:0 5px; border:#6185a2 solid 1px; display:inline-block; padding:2px 6px 1px; line-height:16px; color:#fff; background:#6185a2; } </style> </head> <body> <table align='center'> <tr> <td>id</td><td>姓名</td><td>密码</td><td>性别</td><td>年纪</td><td>邮件</td><td>主页</td><td>薪水</td> </tr> <volist name='res' id='v'> <tr><td>{$v.id}</td><td>{$v.name}</td><td>{$v.password}</td><td>{$v.sex}</td><td>{$v.age}</td><td>{$v.email}</td><td>{$v.mypage}</td><td>{$v.salary}</td></tr> </volist> </table> <div class='pagelist'> {$page} </div> <div align='center'> <br><br> <a style='text-decoration:none' href="{:U('index',array('name'=>'ok'))}"><span style='border:1px solid green;background-color:green;color:white;border-radius:10px;padding:10px'>名字为ok的列表</span></a><br><br><br> <a style='text-decoration:none' href="{:U('index')}"><span style='border:1px solid green;background-color:green;color:white;border-radius:10px;padding:10px'>全部</span></a> </div> </body> </html>
效果图: