View
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>用户信息输出</title> 6 <link href="__ROOT__/Public/Css/style.css" rel="stylesheet" type="text/css" /> 7 <link href="__ROOT__/Public/Css/mypage.css" rel="stylesheet" type="text/css"/> 8 </head> 9 10 <body> 11 <table width="405" border="1" cellpadding="1" cellspacing="1" bgcolor="#99CC33" bordercolor="#FFFFFF"> 12 <tr> 13 <td colspan="3" bgcolor="#FFFFFF" class="title" align="center">当前登录用户:{$Think.session.admin}</td> 14 </tr> 15 <tr> 16 <td colspan="3" bgcolor="#FFFFFF" class="title" align="center">用户信息</td> 17 </tr> 18 <tr class="title"> 19 <td bgcolor="#FFFFFF" width="44">ID</td> 20 <td bgcolor="#FFFFFF" width="120">用户名</td> 21 <td bgcolor="#FFFFFF" width="223">密码</td> 22 </tr> 23 <foreach name='select' item='user' > 24 <tr class="content"> 25 <td bgcolor="#FFFFFF"> {$user.id}</td> 26 <td bgcolor="#FFFFFF"> {$user.word}</td> 27 <td bgcolor="#FFFFFF"> {$user.pwd}</td> 28 </tr> 29 </foreach> 30 <tr class="content"> 31 <!--<td colspan="3" bgcolor="#FFFFFF"> {$page}</td>--> 32 <td colspan="3" bgcolor="#FFFFFF"><div class="pages"> 33 {$page} 34 </div></td> 35 </tr> 36 </table> 37 </body> 38 </html>
Controller
1 <?php 2 namespace Home\Controller; 3 use Think\Controller; 4 class IndexController extends Controller { 5 public function index(){ 6 $m = M('users');//连接表单 7 $count = $m->count();//查询数据数量 8 $p = getpage($count,1);//调用function.php下getpage函数 9 $list = $m->field(true)->order('id')->limit($p->firstRow, $p->listRows)->select();//分页 10 $this->assign('select', $list); // 赋值数据集 11 $this->assign('page', $p->show()); // 赋值分页输出 12 $this->display(); 13 } 14 }
Application/Common/Common/function.php插入方法
1 <?php 2 /** 3 * TODO 基础分页的相同代码封装,使前台的代码更少 4 * @param $count 要分页的总记录数 5 * @param int $pagesize 每页查询条数 6 * @return \Think\Page 7 */ 8 function getpage($count, $pagesize = 10) { 9 $p = new Think\Page($count, $pagesize); 10 $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录 第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>'); 11 $p->setConfig('prev', '上一页'); 12 $p->setConfig('next', '下一页'); 13 $p->setConfig('last', '末页'); 14 $p->setConfig('first', '首页'); 15 //$p->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%'); 16 $p->lastSuffix = false;//最后一页不显示为总页数 17 return $p; 18 } 19 ?>
浙公网安备 33010602011771号