ThinkCMF多条件查询sql where条件判断
TP中 Where 条件表达式格式为:
$map['字段名'] = array('表达式', '操作条件');
$map['status'] = array('=', '1');
$map['title'] = array('like', '%测试%');
$map['delete_time'] = array('=', '0');
实际跑起来不知道为什么就变成
where `status` in ('=', '1') and `title` in ('like', '%测试%') and `delete_time` in ('=', '0')
无奈之下换种写法:
$map = array();
$map[] = ['post_status', '=', 1];
$map[] = ['delete_time', '=', 0];
if ( $word != '' ){
$map[] = ['post_title', 'like', '%'.$word.'%'];
}
这个才是我要的结果
Db::name('recruit')
->where($map)
->order('is_top DESC')
->order('published_time DESC')
->paginate(20);