数据库
p_newsclass
包含字段(id,f_id,name)
id:自增
f_d:父 id
name :类目名
---------------------------------------------------------------------------------------------------------------------------------------
nav.php页面-(其中global.php是用于连接数据库的)
<?php
include_once('global.php');
$q1 = mysql_query("select * from `p_newsclass` where `f_id`=0");
while($row1 = mysql_fetch_array($q1)){
$sm_class1[] = $row1;
$q2 = mysql_query("select * from `p_newsclass` where `f_id`=".$row1['id']);
while($row2 = mysql_fetch_array($q2)){
$sm_class2[] = $row2;
}
$smarty->assign("class2",$sm_class2);
//子类循环出来,一定要在循环里面,定义到模板里面,不能在循环外,显示不出子类,切记
}
$smarty->assign("class1",$sm_class1);
$smarty->display("nav.html");
?>
nav.html页面
<ul>
{section name=list loop=$class1}
<li>
{$class1[list].id}{$class1[list].name}
<ul>
{section name=ls loop=$class2}
{if $class1[list].id == $class2[ls].f_id}
<!--这个判断不能少,否则不能对号入座-->
<li>
{$class2[ls].id} {$class2[ls].name}
</li>
{/if}
{/section}
</ul>
</li>
{/section}
</ul>
有什么不懂的可以联系我
QQ:694665111