<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吗?