thinkphp 获取一级分类下所有商品
functionindex(){$shop_cate_mod=D('shop_cate');$cid=isset($_GET['cid'])&&intval($_GET[...
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();
}
我这样只能获取一级分类,不能获取一级分类下面的商品? 展开
$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();
}
我这样只能获取一级分类,不能获取一级分类下面的商品? 展开
3个回答
展开全部
你可以这样
$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();这样就可以了!
$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();这样就可以了!
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以这样
$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级和2级商品的关联字段呢?获取半天传参都没用啊,WHERE里就一个条件?明显语句有问题,getlastsql(),用这个TP函数获取一下编译后的SQL语句,然后输出一下看看,就一目了然了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询