thinkphp 获取一级分类下所有商品
发布网友
发布时间:2022-04-07 06:27
我来回答
共3个回答
热心网友
时间:2022-04-07 07:57
你可以这样
$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)";$procts = $this->order_model->where($where)->order($order.' '.$method)->limit('5')->select();这样就可以了!
热心网友
时间:2022-04-07 09: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)";
$procts = $this->order_model->where($where)->order($order.' '.$method)->limit('5')->select();
热心网友
时间:2022-04-07 10:49
1级和2级商品的关联字段呢?获取半天传参都没用啊,WHERE里就一个条件?明显语句有问题,getlastsql(),用这个TP函数获取一下编译后的SQL语句,然后输出一下看看,就一目了然了。