{foreach from=$DB_RESULTS item="foo_q"} id: {$foo_q->id} Name: {$foo_q->name} {foreachelse} No items were found in the search {/foreach}
前台赋值index.php
$smarty->assign('DB_RESULTS',$db->get_results("select link_id id,link_name name from wp_links"));
mytemplate.tpl 内容如下
<table border="0" cellspacing="0" cellpadding="3">
{foreach from=$DB_RESULTS item="foo_q"}
<tr>
<td>id: {$foo_q->id}</td>
<td>Name: {$foo_q->name}</td>
</tr>
{foreachelse}
<tr>
<td>No items were found in the search </td>
</tr>
{/foreach}
</table>