电商网站中的多条件筛选需求

图片描述

用的thinkphp框架

$search=urldecode(I("search"));
        $this->assign('search',$search);
        if(!empty($_POST)){
        
            //$condition = array();
            $condition['goods_name']=array("like","%$search%");
            //I('brand') ? $condition['brand_id'] = I('brand') : false;
            if(I('brand')){
                $condition['brand_id']=
            }
            //$condition['brand_id'] =80;
            //I('func') ? $condition['func'] = I('func') : false;
            //I('price') ? $condition['shop_price'] = I('price') : false;

            var_dump($condition);

            //$gList = M('Goods')->where($condition)->select();
           
            //echo "<pre>";
            //var_dump($gList);
            //echo "</pre>";
            
            
        }

我这样写的但是 并不能多条件多 多选查询 求大神 讲讲sql怎么写 最好tp的sql写法

阅读 4.4k
3 个回答

多选框筛选其实我也没做过,但应该可以这样做:
选了哪些品牌,就传ID过去,用‘,’分隔,然后后台做处理,把所有ID搞出来,
再用in语法$where['brand_id'] = array('in',array($id1,$id2,));

我是不会 TP 语法,所以并不能写什么给你。
一个条件下多选,在 sql 来说,就使用 in ,就可以了
where brand IN ('a','b') AND fun IN('1','2')

新手上路,请多包涵

多条件,你好好想想mysql里面多条件是什么 and。那么你用TP的时候,就申明一个$where=array();
$where['name']='test_name',
$where['age']='test_age'.....等等。后面直接 find($where)就可以了
$where['brand_id'] = array('in',array($id1,$id2,)); 还是你TP手册没看全

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题