[英]Pass array to where in Codeigniter Active Record
I have a table in my database with adminId and clientId我的数据库中有一个表,其中包含 adminId 和 clientId
There might be 20 records with the adminId of the logged in user and I'm trying to pull a list of clients.登录用户的 adminId 可能有 20 条记录,我正在尝试提取客户端列表。
I am wondering if there is a way i can say something like:我想知道是否有办法可以这样说:
$this->db->where('id', '20 || 15 || 22 || 46 || 86');
I'm trying to do this with dynamic data (you never know how many clients Id's you'll need to pull).我正在尝试使用动态数据执行此操作(您永远不知道需要提取多少个客户端 ID)。 Any ideas?
有任何想法吗?
$this->db->where_in('id', ['20','15','22','42','86']);
参考: where_in
Use where_in()使用where_in()
$ids = array('20', '15', '22', '46', '86');
$this->db->where_in('id', $ids );
From the Active Record docs:来自 Active Record 文档:
$this->db->where_in();
Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate如果合适,生成一个 WHERE 字段 IN ('item', 'item') SQL 查询与 AND 连接
$names = array('Frank', 'Todd', 'James');
$this->db->where_in('username', $names);
// Produces: WHERE username IN ('Frank', 'Todd', 'James')
Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate,生成一个 WHERE 字段 IN ('item', 'item') SQL 查询,如果合适,用 AND 连接,
$this->db->where_in()
ex : $this->db->where_in('id', array('1','2','3'));
Generates a WHERE field IN ('item', 'item') SQL query joined with OR if appropriate生成一个 WHERE 字段 IN ('item', 'item') SQL 查询,如果合适的话用 OR 连接
$this->db->or_where_in()
ex : $this->db->where_in('id', array('1','2','3'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.