smarty二级导航栏

数据库

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值