php - Multi-condition filtering requirements in e-commerce websites
世界只因有你
世界只因有你 2017-05-18 10:46:17
0
3
567

Thinkphp framework used

$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>";
            
            
        }

I wrote it like this, but it cannot be a multi-select query with multiple conditions. Please tell me how to write sql. The best tp sql writing method

世界只因有你
世界只因有你

reply all(3)
给我你的怀抱

In fact, I have never done multi-select box filtering, but it should be possible to do this:
Which brand is selected, just pass the ID, separated by ',', and then do processing in the background to get all the IDs,
then use in Grammar $where['brand_id'] = array('in',array($id1,$id2,));

小葫芦

I don’t know TP grammar, so I can’t write anything to you.
Multiple selections under one condition, in sql, just use in, that’s itin ,就可以了
where brand IN ('a','b') AND fun IN('1','2') where brand IN ('a','b') AND fun IN('1', '2')

过去多啦不再A梦

Multiple conditions, think carefully about what multi-conditions are in MySQL and. Then when you use TP, declare a $where=array();
$where['name']='test_name',
$where['age']='test_age'...etc. Then just find($where) directly
$where['brand_id'] = array('in',array($id1,$id2,)); Or you haven't read the full TP manual

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template