PHP 读取与拼接多维数据案例(读取是个热门分销圈,并读取分销圈成员数量,分销圈发布的线下活动,以及代理的品牌及品牌下的产品)

代码:
//置顶圈子查询 $topquanAll=$db->getAll("select city_id,union_name,union_desc,union_id from ecs_trader_minfo where is_show=1 order by is_master_priority DESC limit 4"); print_r($topquanAll); foreach($topquanAll as $tk=>$tv){ $topquanAll[$tk]['num']=$tk; /*echo $tk.'*'; print_r($tv);*/ //城市查询 $cityRow=$db->getRow("select region_name from ecs_region where region_id='".$tv['city_id']."'"); $topquanAll[$tk]['city_name']=$cityRow['region_name']; //成员查询 $yuannum=$db->getRow("select count(DISTINCT minfo_user_id) as num from ecs_minfo_user where union_id='".$tv['union_id']."' and is_quanzhu=0 and is_quan_check=1"); /*print_r($yuannum);*/ $topquanAll[$tk]['yuannum']=$yuannum['num']; //查询圈成员发布的圈活动 $yuantopic = $db->getAll("SELECT topic_type,topic_id,title FROM ecs_topic where user_id in (select minfo_user_id as user_id from ecs_minfo_user where union_id='".$tv['union_id']."') and show_type=1 order by end_time desc limit 4"); $size=sizeof($yuantopic); $topquanAll[$tk]['yuantopic']=$yuantopic; if($size<4){ //查询该圈发布的技术文章 $limit=4-$size; $zhishiku=$db->getAll("select c.cat_id,c.url_defined,a.title,a.article_id from ecs_article as a join ecs_category as c on a.cat_id=c.cat_id where a.user_id in (select minfo_user_id as user_id from ecs_minfo_user where union_id='".$tv['union_id']."') and a.is_open=1 order by a.article_id DESC limit $limit"); $topquanAll[$tk]['zhishiku']=$zhishiku; } //查询圈品牌 $quanbrand=$db->getAll("select b.brand_id,b.brand_name,b.url_defined from ecs_brand as b join ecs_trader as t on b.brand_id=t.brand_id where t.user_id in (select minfo_user_id as user_id from ecs_minfo_user where union_id='".$tv['union_id']."') and t.is_supplier_check=1 group by b.brand_id order by b.active_score DESC limit 6"); foreach($quanbrand as $bk=>$bv){ //查询该品牌下商品数量 $goodsnum=$db->getRow("select count(*) as num from ecs_goods where brand_id='".$bv['brand_id']."'"); $quanbrand[$bk]['goods_num']=$goodsnum['num']; //获取该品牌下点击量最多的商品 $goodsRow=$db->getRow("select g.cat_id,c.url_defined,g.goods_id,g.original_img from ecs_goods as g join ecs_category as c on c.cat_id=g.cat_id where g.brand_id='".$bv['brand_id']."' order by g.click_count DESC"); $quanbrand[$bk]['goods']=$goodsRow; } $topquanAll[$tk]['quanbrand']=$quanbrand; } print_r($topquanAll); exit;

浙公网安备 33010602011771号