$where = null; //$where = new Where(); if($business_no != '1') { // $where['cia.business_no'] = $business_no; $where = "cia.business_no='".$business_no."'"; }else if($keyword){ $where = ["cia.business_no|pi.customer_name","like","%".$keyword."%"]; } $res = Db::name('ceb_inquiry_apply')->alias("cia") ->leftJoin('pg_inquiry pi','pi.business_no = cia.business_no') //->leftJoin('pg_inquiry_detail pid','pid.inquiry_id= pi.id') ->field('cia.*,if(cia.update_time,cia.update_time,cia.create_time) as time') ->field('pi.bank_name,pi.branch_bank_name,pi.customer_name,cia.business_no as business_no') ->order("time","desc") ->where($where) //->group('pid.inquiry_id') ->paginate($paginate); return $res;报错:查询表达式错误:'cia.business_no|pi.customer_name',如何解决
时间: 2024-03-09 20:50:22 浏览: 63
解析mysql left( right ) join使用on与where筛选的差异
5星 · 资源好评率100%
根据错误信息,查询表达式错误是因为 `$where` 的值应该是一个数组,但是你在第一个条件中给 `$where` 赋值了一个字符串。解决这个问题的方法是将第一个条件中的字符串改为数组形式,如下所示:
```
$where = null;
if ($business_no != '1') {
$where['cia.business_no'] = $business_no;
} else if ($keyword) {
$where['cia.business_no|pi.customer_name'] = ['like', "%".$keyword."%"];
}
```
然后在查询语句中使用 `$where` 变量即可。
阅读全文