CodeIgniter 删除给定数组中的 where 条件和 where not
CodeIgniter Delete where condition and where not in given array
如何 运行 在 Codeigniter 中删除查询。我有一组数组和一个键。在 MySQL 我的查询 运行 完美。
DELETE FROM `TABLE` WHERE `style_id`=2 && `ID` NOT IN (5,9,12)
在 Codeigniter 中如何写 运行 这个查询。我试过下面的代码但没有用。
$ids = '5,9,12';
$this->db->where('style_id', $style_id)->where_not_in('ID', $ids);
$this->db->delete('TABLE');
试试这个
this->db->where('style_id', $style_id);
this->db->where_not_in('ID', $ids);
$this->db->delete('TABLE');
这将用 AND
子句连接两个参数
数据应该是
数组
$ids = array(10, 20, '30);
Id
$style_id = 15;
你可以直接运行这个:
DELETE FROM `TABLE` WHERE `style_id`=2 && `ID` NOT IN (5,9,12)
in $this->db->query("DELETE FROM `TABLE` WHERE `style_id`=2 && `ID` NOT IN (5,9,12)");
// 试一试
$ids = array(5,9,12);
$style_id =2;
$this->db->where('ID', $style_id);
$this->db->where_not_in('ID', $ids);
$this->db->delete('TABLE');
试试这个:你必须有 $ids 作为数组
$ids = array(5,9,12);
$style_id= 2;
$this->db->where('style_id', $style_id);
$this->db->where_not_in('ID', $ids);
$this->db->delete('TABLE');
如果你喜欢,可以单行写:
$this->db->delete('table name',array('field1'=>'value1','field2 !='=>'value2'));
简短。
如何 运行 在 Codeigniter 中删除查询。我有一组数组和一个键。在 MySQL 我的查询 运行 完美。
DELETE FROM `TABLE` WHERE `style_id`=2 && `ID` NOT IN (5,9,12)
在 Codeigniter 中如何写 运行 这个查询。我试过下面的代码但没有用。
$ids = '5,9,12';
$this->db->where('style_id', $style_id)->where_not_in('ID', $ids);
$this->db->delete('TABLE');
试试这个
this->db->where('style_id', $style_id);
this->db->where_not_in('ID', $ids);
$this->db->delete('TABLE');
这将用 AND
子句连接两个参数
数据应该是
数组
$ids = array(10, 20, '30);
Id
$style_id = 15;
你可以直接运行这个:
DELETE FROM `TABLE` WHERE `style_id`=2 && `ID` NOT IN (5,9,12)
in $this->db->query("DELETE FROM `TABLE` WHERE `style_id`=2 && `ID` NOT IN (5,9,12)");
// 试一试
$ids = array(5,9,12);
$style_id =2;
$this->db->where('ID', $style_id);
$this->db->where_not_in('ID', $ids);
$this->db->delete('TABLE');
试试这个:你必须有 $ids 作为数组
$ids = array(5,9,12);
$style_id= 2;
$this->db->where('style_id', $style_id);
$this->db->where_not_in('ID', $ids);
$this->db->delete('TABLE');
如果你喜欢,可以单行写:
$this->db->delete('table name',array('field1'=>'value1','field2 !='=>'value2'));
简短。