smarty 显示Tbale 有没有好的例子啊

xihuluyou 2006-03-17 06:02:38
表new的字段
id,tiele,cont,link,hits
要显示出来的是
<table>
<tr>
<td>$id</td>
<td><a href="$link">&title</a></td>
<td>$hits</td>
</tr>
<tr>
<td>$id</td>
<td><a href="$link">&title</a></td>
<td>$hits</td>
</tr>
......
</table>

<?php
require('libs/Smarty.class.php');
$smarty = new Smarty;
$db = new mysqli('localhost','root','55555','test');
$query ="select * from new where";
$result = $db->query($query);
$num_results = $result->num_rows;
$row = $result->fetch_row();

$smarty->assign('data',$row);
$smarty->assign('tr',array('bgcolor="#eeeeee"','bgcolor="#dddddd"'));
$smarty->display('table.tpl');
?>
只找到上面的例子,可是和要求不符合啊.
具体怎么弄的,有朋友能给个例子吗?
...全文
69 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
julychina 2006-03-18
  • 打赏
  • 举报
回复
<table>
{foreach key=key item=item from=$result}
<tr>
<td>{$item.id}</td>
<td><a href="$link">&title</a></td>
<td>{$item.hits}</td>
</tr>
{foreachelse}
<tr>
<td>不存在</td>

</tr>
{/foreach}
</table>

<?php
require('libs/Smarty.class.php');
$smarty = new Smarty;
$db = new mysqli('localhost','root','55555','test');
$query ="select * from new where";
$result = $db->query($query);
//$num_results = $result->num_rows;
//$row = $result->fetch_row();

$smarty->assign('$result',$$result);
$smarty->assign('tr',array('bgcolor="#eeeeee"','bgcolor="#dddddd"'));
$smarty->display('table.tpl');
?>
你上面的例子用的是smarty吗?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧