代码如下 | 复制代码 |
php $result=mysql_query("SELECT id,description,parent_id,name,sort_order FROM article_categoey WHERE parent_id=0 order by id"); while ($row = mysql_fetch_array($result)){ $class[]=$row; //$row['id']是分类id,parent_id是子分类所属id $result_sub=mysql_query("SELECT id,description,parent_id,name,sort_order FROM article_categoey WHERE parent_id='".$row['id']."' order by id"); while ($row_sub = mysql_fetch_array($result_sub)) { $subclass[]=$row_sub; } $smarty->assign("subclass", $subclass); } $smarty->assign("class", $class); $smarty->display('articles.html'); ?> |
代码如下 | 复制代码 |
{foreach name=cat from=$class item=cat} {foreach name=subcat from=$subclass item=subcat} {if $subcat.parent_id==$cat.id} {/if} {/foreach} {/foreach} |