自学内容网 自学内容网

thinkphp:数据库复合查询-OR的使用

完整代码

$data['info'] = db::table('po_headers_all')
            ->alias('ph') //设置wip_jobs_all的别名
            ->join(['vendors' => 've'], 'ph.vendor_code=ve.vendor_code')
            ->field('ph.po_num,ph.status,ph.vendor_code,ve.vendor_name,ph.po_all_amount,ph.note,ph.order_date,ph.need_date,ph.creation_date,ph.created_by')
            ->where(function ($query) {
                $query->where('ph.status', '=', 'INPROCESS')
                      ->whereOr('ph.status', '=', '待签核');
            })
            ->where([
                'ph.po_num' => ['like', '%' . $like_num . '%']
            ])
          ->limit($start,$pageSize)
          ->order('ph.po_num desc')
          ->select();

核心

表名可以查询表po_headers_all的status字段即可以为INPROCESS也可以为待签核的数据

->where(function ($query) {
        $query->where('ph.status', '=', 'INPROCESS')
                   ->whereOr('ph.status', '=', '待签核');
})


原文地址:https://blog.csdn.net/weixin_46001736/article/details/140328166

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!