$condition['kname'] = array(array('like','%保健%'), array('like','%护膝%'), array('like','%保健护膝护腰护颈%'), 'or');
如果是动态的多个条件可以如下:
$condition['question'] = array('or');
foreach ($keyword as $value) {
array_unshift( $condition['question'], array('like', '%'.$value.'%'));
}
使用原生拼接,则如下,显然没有上述方法好
$sql = 'select count(*) from '.$item['table_name'].' where ';
foreach ($keyword as $value) {
$sql .= ' `question` like '.'"%'.$value.'%"'.' or';
}
$sql = substr($sql, 0, -2);
$sql.= ' and is_delete=0';
$item_total = Db::query($sql);
$data[$key]['total'] = $item_total[0]['count(*)'];