smarty显示topN条记录

发布时间:2009-08-15 11:55:51 阅读:1044次

toplist.tpl
<html>
<head>
<title>显示多条记录</title>
</head>
<body>
<table border=1>
<{section name=loop loop=$log}>
 <tr>
  <td height=24><a href="/siyublog/logshow.php?id=<{$log[loop].logid}>&classid=<{$log[loop].logclassid}>" target="_blank"><{$log[loop].title}></a></td>
 </tr>
<{/section}>
</table>
</body>
</html>
toplist.php
<?php
 include("conn.php");
 require("../libs/smarty.class.php");
 $smarty = new Smarty();
 $smarty->template_dir = 'templates/'
 $smarty->compile_dir = 'templates_c/'
 $smarty->config_dir = 'configs/'
 $smarty->cache_dir = 'cache/'
 $smarty->caching = false;
 $smarty->left_delimiter="<{";
 $smarty->right_delimiter="}>";
 $sql="select id,logclassid,title from log order by datetime desc limit 0,5 ";
 mysql_query("set names gb2312");
 $query=mysql_query($sql);
 while($row=mysql_fetch_array($query)){
  $array[]= array("logid"=>$row["id"],"logclassid"=>$row["logclassid"],"title"=>$row["title"]);
 }
 $smarty->assign("log", $array);
 $smarty->display("toplist.tpl");
?>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
上一篇:smarty教程
下一篇:smarty实现换行

转载请注明:smarty显示topN条记录 出自老鄢博客 | 欢迎分享