循环嵌套问题求助
2016-07-07 15:00 来源:www.chinab4c.com 作者:ecshop专家
这个说实话· ·不懂哦··· |
回答:
错误还是比较多的: 我现在要在这个嵌套分类循环基础上面增加一个商品展示程序比如:有两个一级分类 A 和B在A 分类下面又有小分类 A_1,A_2,A_3。B分类下面有 B_1,B_2,B_3。在上面嵌套分类循环下面我要显示出A分类下面小分类的产品 同时要包括分类A的产品, B分类同理。求解。我自己在那基础上写了一个 但是貌似不行 不知道哪里写错了 我贴出来 : function index_get_newjiadao22() { $type = $GLOBALS['db']->getAll("SELECT * FROM ecs_category WHERE parent_id=0"); foreach($type AS $key => $typename){ $hid = $typename['cat_id']; $typeone[$hid] = $GLOBALS['db']->getAll("SELECT * FROM ecs_category WHERE parent_id=$hid"); $sa = $typeone[$hid]; foreach($sa AS $sva => $typegood){ $gid = $typegood['cat_id']; $goods[$gid] = $GLOBALS['db']->getAll("SELECT goods_id,cat_id,goods_name,market_price,shop_price,goods_thumb FROM ecs_goods WHERE cat_id=$gid AND is_delete=0 ORDER BY goods_id DESC LIMIT 0,3"); var_dump($goods); } } $sves['type'] = $type; $sves['typeone'] = $typeone; $sves['goods'] = $goods; return $sves; } 模板页代码为: <!--{foreach from=$type item=type}--> <div class="rr"> <div class="dd1"> <div class="dd1_1"> <div class="dd1_1_1 lf">{$type.cat_name}</div> <div class="dd1_1_2 lf"> <!--{foreach from=$typeone[$type.cat_id] item=typeone}--> <a href="category.php?id={$typeone.cat_id}">{$typeone.cat_name}</a>| <!--{/foreach}--> </div> <div class="dd1_1_3 rg"><a href="category.php?id={$type.cat_id}">查看更多>></a></div> <div class="clear"></div> </div> </div> <div class="rr1"> <div class="rr1_1 lf"> <a href="{$type.cat_desc}"><img src="{$type.keywords}" width="372" height="424" style="border:1px solid #c38c86;" class="imgs"></a> </div> <div class="rr1_2 lf"> <ul> <!--{foreach from=$goods[$typeone.cat_id] item=goods key=t}--> <li> <div class="divr1"><a href="goods.php?id={$goods.goods_id}"><img src="{$goods.goods_thumb}" width="170" height="141" style="border:1px solid #e0e0e1;"></a></div> <div class="divr2"><a href="">333{$goods.goods_name}</a></div> <div class="divr3"><span class="spanr1">{$goods.market_price}</span><span class="spanr2">{$goods.shop_price}</span></div> </li> <!--{/foreach}--> <div class="clear"></div> </ul> </div> <div class="clear"></div> </div> </div> <!--{/foreach}--> 麻烦看看哪里有问题 。谢谢 |
错误还是比较多的: 我现在要在这个嵌套分类循环基础上面增加一个商品展示程序比如:有两个一级分类 A 和B在A 分类下面又有小分类 A_1,A_2,A_3。B分类下面有 B_1,B_2,B_3。在上面嵌套分类循环下面我要显示出A分类下面小分类的产品 同时要包括分类A的产品, B分类同理。求解。我自己在那基础上写了一个 但是貌似不行 不知道哪里写错了 我贴出来 : function index_get_newjiadao22() { $type = $GLOBALS['db']->getAll("SELECT * FROM ecs_category WHERE parent_id=0"); foreach($type AS $key => $typename){ $hid = $typename['cat_id']; $typeone[$hid] = $GLOBALS['db']->getAll("SELECT * FROM ecs_category WHERE parent_id=$hid"); $sa = $typeone[$hid]; foreach($sa AS $sva => $typegood){ $gid = $typegood['cat_id']; $goods[$gid] = $GLOBALS['db']->getAll("SELECT goods_id,cat_id,goods_name,market_price,shop_price,goods_thumb FROM ecs_goods WHERE cat_id=$gid AND is_delete=0 ORDER BY goods_id DESC LIMIT 0,3"); var_dump($goods); } } $sves['type'] = $type; $sves['typeone'] = $typeone; $sves['goods'] = $goods; return $sves; } 模板页代码为: <!--{foreach from=$type item=type}--> <div class="rr"> <div class="dd1"> <div class="dd1_1"> <div class="dd1_1_1 lf">{$type.cat_name}</div> <div class="dd1_1_2 lf"> <!--{foreach from=$typeone[$type.cat_id] item=typeone}--> <a href="category.php?id={$typeone.cat_id}">{$typeone.cat_name}</a>| <!--{/foreach}--> </div> <div class="dd1_1_3 rg"><a href="category.php?id={$type.cat_id}">查看更多>></a></div> <div class="clear"></div> </div> </div> <div class="rr1"> <div class="rr1_1 lf"> <a href="{$type.cat_desc}"><img src="{$type.keywords}" width="372" height="424" style="border:1px solid #c38c86;" class="imgs"></a> </div> <div class="rr1_2 lf"> <ul> <!--{foreach from=$goods[$typeone.cat_id] item=goods key=t}--> <li> <div class="divr1"><a href="goods.php?id={$goods.goods_id}"><img src="{$goods.goods_thumb}" width="170" height="141" style="border:1px solid #e0e0e1;"></a></div> <div class="divr2"><a href="">333{$goods.goods_name}</a></div> <div class="divr3"><span class="spanr1">{$goods.market_price}</span><span class="spanr2">{$goods.shop_price}</span></div> </li> <!--{/foreach}--> <div class="clear"></div> </ul> </div> <div class="clear"></div> </div> </div> <!--{/foreach}--> 麻烦看看哪里有问题 。谢谢 |
错误还是比较多的: 我现在要在这个嵌套分类循环基础上面增加一个商品展示程序比如:有两个一级分类 A 和B在A 分类下面又有小分类 A_1,A_2,A_3。B分类下面有 B_1,B_2,B_3。在上面嵌套分类循环下面我要显示出A分类下面小分类的产品 同时要包括分类A的产品, B分类同理。求解。我自己在那基础上写了一个 但是貌似不行 不知道哪里写错了 我贴出来 : function index_get_newjiadao22() { $type = $GLOBALS['db']->getAll("SELECT * FROM ecs_category WHERE parent_id=0"); foreach($type AS $key => $typename){ $hid = $typename['cat_id']; $typeone[$hid] = $GLOBALS['db']->getAll("SELECT * FROM ecs_category WHERE parent_id=$hid"); $sa = $typeone[$hid]; foreach($sa AS $sva => $typegood){ $gid = $typegood['cat_id']; $goods[$gid] = $GLOBALS['db']->getAll("SELECT goods_id,cat_id,goods_name,market_price,shop_price,goods_thumb FROM ecs_goods WHERE cat_id=$gid AND is_delete=0 ORDER BY goods_id DESC LIMIT 0,3"); var_dump($goods); } } $sves['type'] = $type; $sves['typeone'] = $typeone; $sves['goods'] = $goods; return $sves; } 模板页代码为: <!--{foreach from=$type item=type}--> <div class="rr"> <div class="dd1"> <div class="dd1_1"> <div class="dd1_1_1 lf">{$type.cat_name}</div> <div class="dd1_1_2 lf"> <!--{foreach from=$typeone[$type.cat_id] item=typeone}--> <a href="category.php?id={$typeone.cat_id}">{$typeone.cat_name}</a>| <!--{/foreach}--> </div> <div class="dd1_1_3 rg"><a href="category.php?id={$type.cat_id}">查看更多>></a></div> <div class="clear"></div> </div> </div> <div class="rr1"> <div class="rr1_1 lf"> <a href="{$type.cat_desc}"><img src="{$type.keywords}" width="372" height="424" style="border:1px solid #c38c86;" class="imgs"></a> </div> <div class="rr1_2 lf"> <ul> <!--{foreach from=$goods[$typeone.cat_id] item=goods key=t}--> <li> <div class="divr1"><a href="goods.php?id={$goods.goods_id}"><img src="{$goods.goods_thumb}" width="170" height="141" style="border:1px solid #e0e0e1;"></a></div> <div class="divr2"><a href="">333{$goods.goods_name}</a></div> <div class="divr3"><span class="spanr1">{$goods.market_price}</span><span class="spanr2">{$goods.shop_price}</span></div> </li> <!--{/foreach}--> <div class="clear"></div> </ul> </div> <div class="clear"></div> </div> </div> <!--{/foreach}--> 麻烦看看哪里有问题 。谢谢 |
逻辑就是父接点的ID做为 key去组成数组 |
最近更新
常用插件
- ecshop分类批量扩展插件
ecshop分类批量扩展插件,这个插件是ecshop插件里面比较核心的插件。我们...
- ecshop商品分类名称增加样
ecshop插件介绍:本插件可以方便在后台管理,为ecshop商品分类名称增加样...
- ecshop二次商品订购人信息
ecshop二次商品订购人信息填写插件,有时候给朋友送花,或者是送礼品的...
- ecshop二次开发详细页面生
插件介绍: ECSHOP系统,在很多时候,很多商品没有人购买,不但购买的人...
- ecshop2.7.1打印发货单插件
ecshop2.7.1打印发货单插件介绍:ecshop2.7.1和以前的ecshop版本不一样,ecs...
ecshop热门问答
ecshop热门资料
ecshop转化率
ecshop京东
ecshopgram
ecshop撑破
ecshop体力
ecshopfittings
ecshop数据库问题
ecshop与discuz整合
ecshop注册码
ecshop传销
ecshopface
ecshop飞龙
ecshop146
ecshop操作系统
ecshopdisplay
ecshop苹果
ecshop关连
ecshop怀念
ecshop范围
ecshop文档
ecshopoffice
ecshop产品名称
HDWiki
ecshop搬家
ecshop邮件群发管理
ecshopjson类使用
dedecms随机调用
ecshop359199843
ecshop假死
ecshop平板电脑