Thinkphp或查询使用

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 );
posted @ 2018-08-23 16:49  TBHacker  阅读(1085)  评论(0编辑  收藏  举报