);
$smarty->assign('contacts',$data);
?>
//section不用嵌套,因为只有一个数组,数组内部用$contacts[customer]得到
//每个数组,再用.键名来得到键值
{section name=customer loop=$contacts}
name: {$contacts[customer].name}
home: {$contacts[customer].home}
cell: {$contacts[customer].cell}
e-mail: {$contacts[customer].email}
{/section}
The above example will output:
name: John Smith
home: 555-555-5555
cell: 666-555-5555
e-mail: john@myexample.com
name: Jack Jones
home phone: 777-555-5555
cell phone: 888-555-5555
e-mail: jack@myexample.com
name: Jane Munson
home phone: 000-555-5555
cell phone: 123456
e-mail: jane@myexample.com
5、从数据库查询记录显示,实际上是显示二维数组,其实同上例一样
$sql = 'select id, name, home, cell, email from contacts '
."where name like '$foo%' ";
$smarty->assign('contacts', $db->getAll($sql));
?>
//结果:
| Name> | Home | Cell | Email |
---|
{section name=co loop=$contacts} //第一维
view | //第二维用.号来引用