if ($_GET['machine_type_id']) { $machine_type_id = trim($_GET['machine_type_id']); $where['machine_type_id'] = $machine_type_id;}if ($_GET['keywords']) { $keywords = trim($_GET['keywords']); $map = []; $map['machine_type_name'] = $keywords; $map['keywords'] = array('like', '%'.$keywords.'%'); $map['_logic'] = 'or'; $where['_complex'] = $map;}$where['is_show'] = 1;$where['is_del'] = 0;
这里通过一个变量,巧妙的实现了或查询。
最终生成的语句如下:
SELECT * FROM `tf_photo_tutorial` WHERE ( ( `machine_type_name` = 'D850' ) OR ( `keywords` LIKE '%D850%' ) ) AND ( `is_show` = 1 ) AND ( `is_del` = 0 );