三层嵌套循环 值
2016-07-07 15:02 来源:www.chinab4c.com 作者:ecshop专家
我也跟你一样遇到多层嵌套循环的问题,也想请高手请教,个个都忙呀,我现在的解决方法不知合不合理,但能解决问题,我们写循环的时候老被$goods[$row['goods_id']]['url'] 这个两维数组迷惑 我试过我的代码,想多少层都没问题 function get_brand_tree(){ $sql="select brand_id,brand_name FROM ".$GLOBALS['ecs']->table('brand') . "where is_show=1 order by sort_order LIMIT 6"; $res= $GLOBALS['db']->query($sql); $list = array(); while ($row = $GLOBALS['db']->fetchRow($res)){ $arr['bd_id']=$row['brand_id']; $arr['name']=$row['brand_name']; $i++; $arr['num']=$i; $arr['brand_id']=get_goods_tree($row['brand_id']); $list[] = $arr; } return $list; } function get_goods_tree($bd_id){ $sql = "SELECTg.brand_id,g.goods_id, g.goods_name, g.goods_thumb,g.shop_price ". " FROM " .$GLOBALS['ecs']->table('goods') . " AS g" . " WHERE g.brand_id=$bd_id" . " ORDER BY g.sort_order" . " LIMIT 4"; $res = $GLOBALS['db']->query($sql); $list = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $arr['name']=$row['goods_name']; $arr['price']=price_format($row['shop_price']); $arr['brand_id']=get_goods_tree1($row['brand_id']); $list[] = $arr; } return $list; } function get_goods_tree1($bd_id){ $sql = "SELECTg.brand_id,g.goods_id, g.goods_name, g.goods_thumb,g.shop_price ". " FROM " .$GLOBALS['ecs']->table('goods') . " AS g" . " WHERE g.brand_id=$bd_id" . " ORDER BY g.sort_order" . " LIMIT 4"; $res = $GLOBALS['db']->query($sql); $list = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $arr['name']=$row['goods_name']; $arr['price']=price_format($row['shop_price']); $list[] = $arr; } return $list; } |
回答:
不知道你搞定没 ?你想实现啥功能 |
可以了 代码是对的 |
看不见啥样的啊 |
最近更新
常用插件
- ecshop二次商品订购人信息
ecshop二次商品订购人信息填写插件,有时候给朋友送花,或者是送礼品的...
- ecshop2.7.1打印发货单插件
ecshop2.7.1打印发货单插件介绍:ecshop2.7.1和以前的ecshop版本不一样,ecs...
- ecshop二次开发详细页面生
插件介绍: ECSHOP系统,在很多时候,很多商品没有人购买,不但购买的人...
- ecshop商品分类名称增加样
ecshop插件介绍:本插件可以方便在后台管理,为ecshop商品分类名称增加样...
- ecshop分类批量扩展插件
ecshop分类批量扩展插件,这个插件是ecshop插件里面比较核心的插件。我们...
ecshop热门问答
ecshop热门资料
ecshop单里
ecshop字符
ecshopVISA
ecshop截至日期
ecshop怪事
ecshop官方解决
ecshop卖家
ecshopUCCENTER
ecshop站内快讯
ecshopallocated
ecshopCOD
ecshoplunarpages
ecshop非会员
ecshop声音
ecshop相簿
ecshop报警
ecshop香港
ecshop系统bug
ecshop310
ecshop数据结构
ecshop婴儿
ecshopdoesn
ecshopsuccesful
ecshopphpwind
ecshop网站模板
ecshop广告图片
ecshop一步购物
ecshop工作者
ecshop邮费
ecshop413