第一个smarty例子--分页显示数据

模板页index.tpl:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns=" http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>查看留言</title>
<styletype="text/css">
<!--
.STYLE1{color:#FF0000}
-->
</style>
</head>
<body>
<{*assignvar="login"value=0*}>
<divalign="center">
<p><ahref="index.php">主页</a>  <ahref="addmeg.php">留言</a> 
<{if$login==0}> <ahref="gli.php">管理</a><{/if}>  <{*login=0未登陆,显示管理链接*}>
</p>
</div>
<{sectionname=lploop=$ly}>
<tablewidth="590"border="1"align="center"cellpadding="0"cellspacing="1">
<tr>
<tdwidth="85"rowspan="2"><p>留言人:<br/>
<{$ly[lp].fbr}></p>
</td>
<tdwidth="427"height="23"><p> 标题:<{$ly[lp].tm}></p>
</td>
</tr>
<tr>
<tdheight="58"> 内容:<{$ly[lp].nr}></td>
</tr>
</table><br/>
<{/section}>
<palign="center">总<spanclass="STYLE1"><{$pcunt}></span>页 当前为第<spanclass="STYLE1"><{$page}></span>页 <ahref="index.php">首页</a> <{$qian}><{$next}><ahref="index.php?page=<{$pcunt}>">最后一页</a></p>
</body>
</html>
//
index.php:
<?php
/*********************************************
*
*文件名:index.php
*作用:显示留言分页
*作者:龙的心
*QQ:282129207
*
*********************************************/

require("./class/Smarty.class.php");//包含smarty类文件
$smarty=newSmarty();//建立smarty实例对象$smarty
$smarty->template_dir='./templates/';
$smarty->compile_dir='./templates_c/';
$smarty->config_dir='./configs/';
$smarty->cache_dir='./cache/';
$smarty->caching=false;//这里是调试时设为false,发布时请使用true
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";


mysql_connect('localhost','root','root');
mysql_select_db('nihao');
mysql_query("setnames'gb2312'");
$page=$_GET['page'];
if($page==null)
$page=1;
$psize=4;//每页记录数
$str="select*fromly";
$query=mysql_query($str);
$num=@mysql_num_rows($query);//总记录数
$pcunt=ceil($num/$psize);//总页数
$nextpage=$page+1;
$qianpage=$page-1;
$start=($page-1)*$psize;

$str="select*fromlylimit$start,$psize";
$query=mysql_query($str);
while($arr=mysql_fetch_array($query))
{//print_r($arr);
$array[]=$arr;
}
if($page>1)$str1="<ahref=index.php?page=$qianpage>上一页</a> ";
if($page<$pcunt)$str2="<ahref=index.php?page=$nextpage>下一页</a> ";
$smarty->assign("login","0");//login=0未登陆,显示管理链接
$smarty->assign("ly",$array);
$smarty->assign("page",$page);
$smarty->assign("qian",$str1);
$smarty->assign("next",$str2);
$smarty->assign("pcunt",$pcunt);
$smarty->display("index.tpl");
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值