$value = array('one', 'two', 'three');
我有这部分查询:
$features_filter .= $this->db->placehold('AND p.id in (SELECT product_id FROM __options WHERE feature_id=? AND value in (?@) ) ', $feature, $value);
该查询仅在数据库包含值=='一个'或者'两个'或者'三'。 如何更改我的查询以执行该查询返回了一些LIKE' one'或者'两个'或者'三'?
PS抱歉我的英文不好
答案 0 :(得分:0)
这是一个快速而肮脏的解决方案:
$value = array('one', 'two', 'three');
for ($i = 0; $i < sizeof($value); $i++ ):
$new .= " LIKE '%$value[$i]%'";
if ( $i < sizeof($value) -1 ) :
$new .= " OR";
endif;
endfor;
$features_filter .= $this->db->placehold('AND p.id in (SELECT product_id FROM __options WHERE feature_id=? AND value ' . $new ) ', $feature );
添加:在PHP&gt; = 5.3上,for
- 循环也可以替换为此代码:
array_walk( $value, function (&$value, $key) {
$value = " LIKE %$value%";
});
$new = implode(' OR', $value );