Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter,其中在子句中显示或的结果_Php_Mysql_Database_Codeigniter - Fatal编程技术网

Php codeigniter,其中在子句中显示或的结果

Php codeigniter,其中在子句中显示或的结果,php,mysql,database,codeigniter,Php,Mysql,Database,Codeigniter,当在codeigniter中使用where in时,我遇到了一些问题,我想修改不使用and而使用or的子句 代码如下: $this->db->where_in('id','1,2,3'); 它的工作原理如下: $this->db->where('id',1); $this->db->where('id',2); $this->db->where('id',3); $this->db->where('id',1); $this->

当在codeigniter中使用where in时,我遇到了一些问题,我想修改不使用and而使用or的子句

代码如下:

$this->db->where_in('id','1,2,3');
它的工作原理如下:

$this->db->where('id',1);
$this->db->where('id',2);
$this->db->where('id',3);
$this->db->where('id',1);
$this->db->or_where('id',2);
$this->db->or_where('id',3);
$ids = array('1', '2', '3');
$this->db->where_in('id', $ids);
//Produces: WHERE id IN ('1', '2', '3')
$this->db->where_in('id', array('1', '2', '3'));
//Produces: WHERE id IN ('1', '2', '3')
但我想要这样的结果:

$this->db->where('id',1);
$this->db->where('id',2);
$this->db->where('id',3);
$this->db->where('id',1);
$this->db->or_where('id',2);
$this->db->or_where('id',3);
$ids = array('1', '2', '3');
$this->db->where_in('id', $ids);
//Produces: WHERE id IN ('1', '2', '3')
$this->db->where_in('id', array('1', '2', '3'));
//Produces: WHERE id IN ('1', '2', '3')
但它仍然使用where而不是where。谢谢

您的
where_in()
用法错误。必须在
数组中声明要比较的值,如下所示:

$this->db->where('id',1);
$this->db->where('id',2);
$this->db->where('id',3);
$this->db->where('id',1);
$this->db->or_where('id',2);
$this->db->or_where('id',3);
$ids = array('1', '2', '3');
$this->db->where_in('id', $ids);
//Produces: WHERE id IN ('1', '2', '3')
$this->db->where_in('id', array('1', '2', '3'));
//Produces: WHERE id IN ('1', '2', '3')
或者像这样:

$this->db->where('id',1);
$this->db->where('id',2);
$this->db->where('id',3);
$this->db->where('id',1);
$this->db->or_where('id',2);
$this->db->or_where('id',3);
$ids = array('1', '2', '3');
$this->db->where_in('id', $ids);
//Produces: WHERE id IN ('1', '2', '3')
$this->db->where_in('id', array('1', '2', '3'));
//Produces: WHERE id IN ('1', '2', '3')
使用这个怎么样:

$id = array('1', '2', '3');
$this->db->or_where_in('id', $ids);
更新:

$this->db->select()->from('tbl')
   ->group_start()
     ->where('id', 1)
     ->or_group_start()
       ->where('id', 2)
       ->where('id', 3)
     ->group_end()
   ->group_end();

请检查where_in的语法

$this->db->where_in()
在(项,项)
SQL查询中生成一个
WHERE字段,如果合适,与

$ids = array(1, 2, 3);
$this->db->where_in('id', $ids);


$this->db->or_where_in()
$ids = array('1', '2', '3');
$this->db->or_where_in('id', $ids);


$this->db->where_not_in()
$ids = array('1', '2', '3');
$this->db->where_not_in('id', $ids);


$this->db->or_where_not_in()
$ids = array('1', '2', '3');
$this->db->or_where_not_in('id', $ids);
在('item','item')中生成一个
WHERE字段
SQL查询

$ids = array(1, 2, 3);
$this->db->where_in('id', $ids);


$this->db->or_where_in()
$ids = array('1', '2', '3');
$this->db->or_where_in('id', $ids);


$this->db->where_not_in()
$ids = array('1', '2', '3');
$this->db->where_not_in('id', $ids);


$this->db->or_where_not_in()
$ids = array('1', '2', '3');
$this->db->or_where_not_in('id', $ids);
生成一个
WHERE字段不在('item'、'item')
SQL查询,并在适当的情况下与

$ids = array(1, 2, 3);
$this->db->where_in('id', $ids);


$this->db->or_where_in()
$ids = array('1', '2', '3');
$this->db->or_where_in('id', $ids);


$this->db->where_not_in()
$ids = array('1', '2', '3');
$this->db->where_not_in('id', $ids);


$this->db->or_where_not_in()
$ids = array('1', '2', '3');
$this->db->or_where_not_in('id', $ids);
生成一个
WHERE字段不在('item','item')
SQL查询,该查询与或(如果合适)连接

$ids = array(1, 2, 3);
$this->db->where_in('id', $ids);


$this->db->or_where_in()
$ids = array('1', '2', '3');
$this->db->or_where_in('id', $ids);


$this->db->where_not_in()
$ids = array('1', '2', '3');
$this->db->where_not_in('id', $ids);


$this->db->or_where_not_in()
$ids = array('1', '2', '3');
$this->db->or_where_not_in('id', $ids);

有关更多信息,请参阅官方文档

它可以工作,但当只有一个条件且条件与数据不匹配时,结果仍然显示添加您使用的所有代码。请发布您想要得到的结果。你得到了什么结果。也张贴你的样本表。