mysql - 需要帮助以使用 activedataprovider 构建查询
问题描述
我想在 yii2 ActiveDataProvider 中执行以下 WHERE 条件
预期在哪里条件:
$query="WHERE VoterName Like '%s%' AND (contactno != '' OR whatsapp_no!= '')";
我目前的 where 条件:
$query->andFilterWhere(['like', 'VoterName', $this->VoterName]);
$query->orWhere(['<>', 'contactno', ''])->orWhere(['<>', 'whatsapp_no', '']);
我只想获取那些有contactno或whatsapp_no的记录。
解决方案
当您需要设置多个条件时,您必须使用andWhere,例如对于您的问题:
$query->andFilterWhere(['like', 'VoterName', $this->VoterName]);
$query->andWhere(['OR',['<>', 'contactno', ''],['<>', 'whatsapp_no', '']]);
推荐阅读
- laravel - Laravel - 将 TailwindCSS 样式的视图输出为 PDF
- android - 使用带有底部导航的 Android 导航组件时检测选项卡更改
- azure-devops-rest-api - 从测试外部链接和外部链接 ArtifactURI 中查找测试结果 URL
- javascript - javascript:如何将字符串替换保存在另一个字符串中?
- python - Raid alert catch python脚本需要添加Nagios逻辑
- python - 如何使用切片提取列表中的部分项目?
- assembly - 如何在汇编编程语言中分配位域 - NASM
- julia - 使用 Turing.jl 对 AR(2) 进程进行采样时出现 TypeError
- python - Jenkins python脚本没有运行
- php - 单击php中的提交按钮后如何使用id获取此名称