0
点赞
收藏
分享

微信扫一扫

tp5的条件搜索 where和whereor复杂用法实例


tp5的条件搜索 where和whereor复杂用法

实例1:不需要传参数

$room_qualification_count=Db::name("room")  ->where("level",1)  ->where(function ($room_qualification_count)   {
$room_qualification_count->whereOr("a",0);
$room_qualification_count->whereOr("b",0);
$room_qualification_count->whereOr("c",0);
$room_qualification_count->whereOr("d",0);
})->fetchSql(true) ->find();

var_dump($room_qualification_count);die;

SELECT 
*
FROM
`fa_room`
WHERE `level` = '1'
AND ( `a` = 0 OR `b` = 0 OR `c` = 0 OR `d` = 0 )
LIMIT 1

实例2:需要传参

$whereO=1;
$room_qualification_count=Db::name("room") ->where("level",1) ->where(function ($room_qualification_count) use ($whereO) {
$room_qualification_count->whereOr("a",$whereO);
$room_qualification_count->whereOr("b",0);
$room_qualification_count->whereOr("c",0);
$room_qualification_count->whereOr("d",0);
})->fetchSql(true) ->find();

var_dump($room_qualification_count);die;

SELECT
*
FROM
`fa_room`
WHERE `level` = '1'
AND ( `a` = 1 OR `b` = 0 OR `c` = 0 OR `d` = 0 )
LIMIT 1


举报

相关推荐

0 条评论