php - 多个类似推进器的过滤器
问题描述
尝试使用 LIKE 按多个条件过滤列。
像这样:
$d = ItemQuery::create()
->filterByName($array_of_names, Criteria::LIKE)
->find();
但我得到“在 propel/src/Propel/Runtime/Connection/StatementWrapper.php 中的数组到字符串转换”
如何使用“LIKE”标准按多个“名称”过滤?
我基本上希望查询是
...name LIKE %name1% OR name LIKE %name2% OR name LIKE %name2%...
解决方案
假设$array_of_names
是[$name1, $name2, ...]
$q = ItemQuery::create()
foreach ($array_of_names as $i => $name) {
if ($i > 0) { // Not the first item in the array
$q->_or();
}
$q->where('Item.Name LIKE %?%', $name);
}
$d = $q->find();
看
http://propelorm.org/blog/2012/03/20/don-t-do-this-at-home-5-use-where-instead-of-filterby.html
和
或者
推荐阅读
- python - SQLAlchemy 抛出表名的键错误。不知道为什么?请指导
- python - 寻找有关构建从通用文件解析器派生的 XML 解析器的技巧
- ios - dyld:库未加载:@rpath .. 原因:找不到图像
- google-sheets - 使用 Javascript 在 Google 电子表格中插入日期 (yyyy-MM-dd HH:mm:ss) 添加撇号
- javascript - 带有串口本机模块的电子
- javascript - 如果用户当前的时区时间与“开放时间”(ES6)一致,则显示 div
- r - 删除 R Leaflet 中的特定图层
- r - 如果在公式参数中使用点,为什么 r 聚合求和会产生错误的结果?
- python - Python asyncio NotImplementedError
- excel - 如何从数据透视表中过滤出所有“字符串”