我有类别和子类别。我想选择所有父类别和子类别。但只想在每个父类别下显示 3-4 个子类别。
我的 PHP代码
/******Start Categories********/
$ca=mysql_query('select * from category where parent_id=0');
while($ca1 = mysql_fetch_array($ca))
{
$ca2[]=$ca1;
}
$smarty->assign('ca2',$ca2);
/******End Categories********/
/******Start SubCategories********/
$sub=mysql_query('select * from category where parent_id!=0 ');
while($sub1 = mysql_fetch_array($sub))
{
$sub2[]=$sub1;
}
$smarty->assign('sub2',$sub2);
/******End SubCategories********/
和 Tpl代码:
<div id="sub_ltcol">
{section name=loopc loop=$ca2}
<div id="gr_design">
<div id="gr_head">
<h4>{$ca2[loopc].category_name}</h4>
</div>
{section name=loops loop=$sub2}
{if $ca2[loopc].category_id eq $sub2[loops].parent_id}
<div id="gr_body">
<ul>
<li>
<div class="arw_icon"><img src="images/arw_icon.png"></div>
<a href="#">{$sub2[loops].category_name}</a>
</li>
<div class="dotted_line"></div>
</ul>
</div>{/if}
{/section}
</div>
{/section}
</div>
我只想显示<li>
标签 3-4 次。