【发布时间】:2019-09-19 20:59:13
【问题描述】:
我想搜索从 Excel 复制的多个项目。这些 sku 由空白区域隔开。搜索结果始终为空,因为每个条件都应该是 OR 而不是 AND。如何将分页条件从 AND 更改为 OR?
查询结果
SELECT *, ParentProduct.id FROM parent_products AS ParentProduct WHERE
ParentProduct.name LIKE '%na301mo%' AND ParentProduct.name LIKE '%gf001bh%' AND
ParentProduct.name LIKE '%cc302bf%' LIMIT 10
搜索值
na301mo gf001bh cc302bf
控制器
if (empty($results)) {
$this->paginate['conditions'] = $this->ParentProduct->resetConditions($searchStr, 'multi-skus');
$results = $this->paginate('ParentProduct');
}
型号
public function resetConditions($searchStr, $opt) {
if ($opt == ‘multi-skus’) {
$conditions = array();
$searchStr = preg_replace('!\s+!', ' ', $searchStr);
$search_terms = explode(' ', $searchStr);
foreach ($search_terms as $search_term) {
$conditions[] = array($this->name . '.sku LIKE' => '%' . $search_term . '%');
}
}
}
版本。 1.3 倍
请指教。 谢谢
【问题讨论】:
标签: cakephp