继续提问,继续学习,继续进步

#1 none110

{foreach from=$bigcate item=results}
  
  {if $smallcate->VCFatherId eq $bigcate->VCId}
     {foreach from=$smallcate item=results2}  
         
   
     
    {/foreach}
   {/if}
  {/foreach}

可是为什么每一个大类下面都重复下面的小类?

control中写的

  $condition="VCFatherId = 0";
  $condition2="VCFatherId <> 0";
  $this->bigcate = spClass("lib_addcate")->findAll($condition);
  $this->smallcate = spClass("lib_addcate")->findAll($condition2);
  $this->display("/manager/addcate.html");


我绝对是思路有问题了,还望给指点下。。。

2011-07-06 16:36:11

#2 jake

if和里面的foreach位置交换一下
{foreach from=$smallcate item=results2}  
  {if $results2->VCFatherId eq $results->VCId}

2011-07-06 18:48:30

#3 none110

这种写法有没有问题呢?有没有更高效点的写法?

2011-07-07 09:28:59

#4 none110

运行后发现,每个一级分类下面都会有相同的二级分类

2011-07-07 09:53:47

#5 none110

搞定了。

  {foreach from=$bigcate item=results}
  

            {foreach from=$smallcate item=results2}        
                  {if $results2.VCFatherId == $results.VCId}
                
                         {/if}
                  {/foreach}

  {/foreach}

改为这样。

望jake给个更高效的方法。

2011-07-07 10:14:53

#6 jake

用关联查找

2011-07-07 13:22:57