Codeigniter查询构建器在where_in中使用爆破功能 [英] Codeigniter query builder using implode function in where_in
本文介绍了Codeigniter查询构建器在where_in中使用爆破功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我使用爆破功能的普通SQL查询:
Here is my normal sql query using implode function:
SELECT * from search_result WHERE skills IN ('".implode("','",$s_id)."');
现在,我想将其转换为codeigniter形式.我尝试了以下代码,但失败了
Now I want to convert this to codeigniter form. I tried the following code but it fails
$this->db->from('search_result');
$this->db->where_in('skills','".implode("','",$s_id)."');
$query = $this->db->get();
这是我的$s_id
数组:
Array ( [0] => 2D Design [1] => 3D Design [2] => 3D Modelling )
所以任何人都可以帮助我做到这一点.在此先感谢:)
So anyone please help me to do this. Thanks in advance :)
推荐答案
官方文档说的
$names = array('Frank', 'Todd', 'James'); # Data Array
$this->db->where_in('username', $names); # passing array
尝试如下
Try like below
方法01 (推荐)
$this->db->from('search_result');
$this->db->where_in('skills',$s_id);
$query = $this->db->get();
方法02
$this->db->from('search_result');
$this->db->where_in('skills',implode("','",$s_id));
$query = $this->db->get();
此行有什么问题
$this->db->where_in('skills','".implode("','",$s_id)."');
不要用'
或"
引号将函数引起来.然后将其另存为STRING值到DB.
don't wrap function with '
or "
quotes. Then it will get save as STRING value to DB.
链接
where_in
clause in codeigniter.com
这篇关于Codeigniter查询构建器在where_in中使用爆破功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文