合作&赞助



管理员登录
用户名:
密 码:
技术文章 > PHP

thinkphp-留言板(四) - 分页显示
Description:为了提升一层次,决定尝试thinkphp开发个项目. 不过咱啥也不懂,先看看实例。。。
Source Url:http://hi.baidu.com/waterjiang/blog/item/665d144d635df63cafc3ab97.html
 现在就是要吧数据取出来了,当然还得分页显现。
a):打开IndexAction.calss.php,在index函数里面修改为如下代码:

    public function index(){
$xian=D("Liuyan");
$count = $xian->count('','id');//计算所有行
$listRows = '3';//每页显示的行数
$fields = 'id,name,email,qq,title,con';//需要查询哪些字段
import("ORG.Util.Page");//导入分页类 /ThinkPHP/lib/ORG/Util/Page.class.php
$p = new Page($count,$listRows);//通过类的构造函数来改变page的参数。$count为总数,$listrows为每一页的显示条目。
//设置查询参数。具体见“ThinkPHP/Lib/Think/Core/Model.class.php"1731行。
$list = $xian->findall('',$fields,'id desc',$p->firstRow.','.$p->listRows);

//模板输出
$page=$p->show();
$this->assign('list',$list);
$this->assign('page',$page);
$this->display();


}
b):打开index.html页面,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<include file="Index:head" />
<volist name='list' id='vo'> //name 就是要显示的内容(控制器里发送过来的)与smarty模板相似,id相当于as,别名。
<table width="562" height="118" border="1" align="center">
<tr>
<td width="97" rowspan="2">留言人:{$vo.name}</td>
<td width="286" height="36">主题:{$vo.title}</td>
<td width="59"><a href="{$vo.email}" target="_blank">邮箱</a></td>
<td width="92"><A target="blank" href="tencent://message/?uin={$vo.qq}&Menu=yes"><IMG border="0" src="http://wpa.qq.com/pa?p=1:
{$vo.qq}:1" alt="有事点这里"></A></td>
</tr>
<tr>
<td height="74" colspan="3">{$vo.con}</td>
</tr>
</table>

</volist>
<table width="562" height="30" border="1" align="center">
<tr>
<td align="center">{$page}</td>
</tr>
</table>
<include file="Index:bottom"/>

</body>
</html>

我们将看到效果:

这样留言板的基本功能就实现了。


使用时间:0.890926122665 秒