smarty显示topN条记录

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");
?>

    A+
发布日期:2009年08月15日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: