function index(){
$shop_cate_mod=D('shop_cate');
$cid = isset($_GET['cid']) && intval($_GET['cid']) ? intval($_GET['cid']) :0;
$shop_cate=$shop_cate_mod->field('id,title')->where("status=1")->order("sort_order ASC")->select();
$this->assign('shop_cate',$shop_cate);
$this->display();
}
我这样只能获取一级分类,不能获取一级分类下面的商品?
thinkphp 获取一级分类下所有商品
答案:3 悬赏:20 手机版
解决时间 2021-04-06 02:12
- 提问者网友:谁的错
- 2021-04-05 23:09
最佳答案
- 五星知识达人网友:孤独的牧羊人
- 2021-04-06 00:15
可以这样
$str = 'select id from tp_order_cat where parentid in (1,5,6)';//获取所有的1,5,6的所有下级分类
$need_list = D('tp_order_cat')->where('parentid in (1,5,6)')->select();//获取到的
$need_id_str = ''; //获取需要的子类id
foreach($need_list as $val){
$need_id[] = $val['id'];
}
$need_id_str = join(',', $need_id);
$where = "catid in ($need_id_str)";
$products = $this->order_model->where($where)->order($order.' '.$method)->limit('5')->select();
$str = 'select id from tp_order_cat where parentid in (1,5,6)';//获取所有的1,5,6的所有下级分类
$need_list = D('tp_order_cat')->where('parentid in (1,5,6)')->select();//获取到的
$need_id_str = ''; //获取需要的子类id
foreach($need_list as $val){
$need_id[] = $val['id'];
}
$need_id_str = join(',', $need_id);
$where = "catid in ($need_id_str)";
$products = $this->order_model->where($where)->order($order.' '.$method)->limit('5')->select();
全部回答
- 1楼网友:怙棘
- 2021-04-06 02:08
你可以这样
$str = 'select id from tp_order_cat where parentid in (1,5,6)';//获取所有的1,5,6的所有下级分类
$need_list = d('tp_order_cat')->where('parentid in (1,5,6)')->select();//获取到的
$need_id_str = ''; //获取需要的子类id
foreach($need_list as $val){
$need_id[] = $val['id'];
}
$need_id_str = join(',', $need_id);
$where = "catid in ($need_id_str)";
$products = $this->order_model->where($where)->order($order.' '.$method)->limit('5')->select();这样就可以了!
- 2楼网友:动情书生
- 2021-04-06 00:48
你可以这样
$str = 'select id from tp_order_cat where parentid in (1,5,6)';//获取所有的1,5,6的所有下级分类$need_list = D('tp_order_cat')->where('parentid in (1,5,6)')->select();//获取到的 $need_id_str = ''; //获取需要的子类idforeach($need_list as $val){ $need_id[] = $val['id'];} $need_id_str = join(',', $need_id);$where = "catid in ($need_id_str)";$products = $this->order_model->where($where)->order($order.' '.$method)->limit('5')->select();这样就可以了!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯