Smarty的嵌套循环
时间:2008-04-18 来源:慕良文王
?php
include_once("./smarty/Smarty.class.php");
include_once("./lib/conn.php");
$s = new Smarty;
//$s->caching = true;//开启缓存功能
$s->template_dir = './tpl';
$s->compile_dir = './compile';
$s->cache_dir = './cache';
$sql="select * from class";
$re=mysql_query($sql);
while($k=mysql_fetch_array($re))
{
$sql="select * from content where class=$k[id]";
$ree=mysql_query($sql);
$news=array();
while($sub=mysql_fetch_array($ree))
{
$news[]=$sub;
}
$k[news_list]=$news;
$cat_news[]=$k;
}
$s->assign("ss",$cat_news);
$s->display("main.html");
?>
{foreach item=list from=$ss}
{$list.class_name}br />
{foreach item=sub_list from=$list.news_list}
{$sub_list.title}br />
{/foreach}
{/foreach}
相关阅读 更多 +