php - codeigniter 中的多列 where_in 子句

标签 php mysql codeigniter where-in

下面是codeigniter单列where_in子句$this->db->where_in('x1',$val);

我如何在 CodeIgniter where_in 子句中传递多个列,如下面的 MySQL 查询 select * from tab1 where (col1,col2) in ((1,2),(2,3) ) 任何帮助表示赞赏

最佳答案

假设你的数据数组是这样的(应该是)

$val1 = array(1,2);
$val2 = array(2,3);

查询应该是

$this->db->select('*');
$this->db->from('tab1');
$this->db->where_in('col1',$val1);
$this->db->or_where_in('col2',$val2);
$query = $this->db->get();
$result = $query->result_array();

否则你可以使用

$this->db->query("select * from tab1 where (col1,col2) in ($val1,$val2)");

关于php - codeigniter 中的多列 where_in 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45708833/

相关文章:

php - laravel Eloquent 关系问题

php - 根据php中的用户输入生成报告

php - 如何显示点击计数器然后使其回到零?

MYSQL存储过程查询回退逻辑

php - php 中 num_rows() 的 mysql 行数可靠吗?

php - CodeIgniter 中日期和时间的验证规则

Codeigniter跳过登录检查,在构造函数中定义,用于特定操作

php - 关于 PHP 范围的问题——从 Java 程序员的角度

php - GROUP_BY 中的错误,查询来自两个数据库 CODEIGNITER

javascript - 使用 JS 和 php 将跨度文本发送到另一个页面