php - 如何使用 codeigniter 在 where 子句中传递数组?

标签 php mysql codeigniter

如何使用 codeigniter 在 where 子句中传递数组变量? 例如,使用如下 SQL 查询:

Select(" item,price Where(userid=123 and proid=3 or userid=124 and proid=3... [upto n user id]userid=nth_id and proid=3");

如果 userid 存储在数组变量中,那么如何在 codeigniter 中创建这样的条件?

最佳答案

我正在寻找这个,它应该寻找数组中的 userid 并且 proid 为 3。我还没有测试过它,但让我们知道您过得怎么样。

$array = array( '123', '124' );
$this->db
     ->select( 'item, price' )
     ->from( 'table')
     ->where( 'proid', '3' )
     ->where_in( 'userid', $array )
     ->get();
$result = $query->result();

关于php - 如何使用 codeigniter 在 where 子句中传递数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40383535/

相关文章:

php - 通过 w3c 验证器的问题

php - 除了这个,还有什么方法可以达到 "figure out the application base dir"吗?

php - MONGODB/PHP SSL连接问题-TLS握手失败

php - Codeigniter:使用数据库存储多个用户的数据库名称

php - Codeigniter 中文本更新和图像的问题

php - Codeigniter 分页链接按降序/倒序排列?

javascript - 使用 404 撤销对某些页面的访问

mysql - Laravel 5.2 Eloquent 关系

mysql max(日期)不工作

php - 如何编写子查询子查询多行父查询单行返回