Php 如何在类似条件下使用Codeigniter中的活动记录?
如何在Codeigniter中使用或类似? 例如,我需要:Php 如何在类似条件下使用Codeigniter中的活动记录?,php,codeigniter,Php,Codeigniter,如何在Codeigniter中使用或类似? 例如,我需要: WHERE type LIKE 'test' OR type LIKE 'test2' 我想应该是这样的: $this->db->like(); $this->db->or_like(); (使用时发现)。您需要同时使用like和/或like $this->db->like('type', 'test', 'none'); $this->db->or_like('type', 'te
WHERE type LIKE 'test' OR type LIKE 'test2'
我想应该是这样的:
$this->db->like();
$this->db->or_like();
(使用时发现)。您需要同时使用like和/或like
$this->db->like('type', 'test', 'none');
$this->db->or_like('type', 'test2', 'none');
将产生
WHERE type LIKE 'test' or type LIKE 'test2'
看不见,看不见,看不见之前,看不见之后
更新在您的示例中,您仅使用2键进行匹配,因此上述解决方案是可行的。
但如果您想匹配五个键,如
test1
test2
test3
test4
test5
,您可以按照以下方法进行匹配
$array=array('test1','test2', 'test3','test4','test5');
foreach($array as $item)
{
$this->db->or_like('type', $item, 'none');
}
您的值中需要百分比字符。。。例如,如果您想让test出现在字符串中的任何位置,可以使用“%test%”。我理解,我的意思是有一个
$\u POST['type'][0]=test$_POST['type'][1]=test2
如何将其转换为查询字符串或数组?如果您无法在谷歌上搜索,请滚动到like()和/或like(),如果使用或like(),我已经读过了;和数组('type'=>'test','type'=>'test2')
它给了我数组('type'=>'test')
@FranceDePerost:你的意思是你的数组可以是任意长度的吗?谢谢,但是如何格式化数组呢?它可以是或_like()