根据TP5.1框架,我的版本是:5.1.37 LTS
文件: thinkphp\library\think\db\Builder.php
第329行: } elseif (strpos($field, '|')) {
表示,如果字段中带有竖线 , 则替换为 OR 字符
$where = [];
$where[] = ['is_publish', '=', 1];
if(isset($_POST['city']) && $_POST['city'] != ''){
$city = input('post.city/s', 'trim');
$where[] = ['region', 'LIKE', '%'.$city.'%'];
}
if(isset($_POST['district']) && $_POST['district'] != ''){
$district = input('post.district/s', 'trim');
$where[] = ['region', 'LIKE', '%'.$district.'%'];
}
if(isset($_POST['keyword']) && $_POST['keyword'] != ''){
$keyword = input('post.keyword/s', 'trim');
$where[] = ['business | position', 'LIKE', '%'.$keyword.'%']; // OR查询
}
$sel ectPosition = Db::name('position')->where($where)->order("orderno DESC, id DESC")->limit(10)->sel ect();
dump(Db::getLastSql());
查询结果:
SELECT * FROM `recruit_position` WHERE `is_publish` = 1 AND `region` LIKE '%深圳%' AND ( `business` LIKE '%华为%' OR `position` LIKE '%华为%' ) ORDER BY `orderno` DESC,`id` DESC LIMIT 10
最佳答案