Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.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 在where条件下使用数组_Php_Sql_Sql Server_Codeigniter - Fatal编程技术网

Php 在where条件下使用数组

Php 在where条件下使用数组,php,sql,sql-server,codeigniter,Php,Sql,Sql Server,Codeigniter,我有一个名为$req\u dep的数组数据。下面是当我var\u dump()it时它的样子 array(2) { [0]=> int(41) [1]=> int(765) } 我想在查询中使用这些数据 select * from dbo.RequisitionTable where RequestorID = '$ID' and RequestorDepartmentID in ($req_dep) and IsProcessedToHire=0 and

我有一个名为
$req\u dep
的数组数据。下面是当我
var\u dump()
it时它的样子

array(2) { [0]=> int(41) [1]=> int(765) }
我想在查询中使用这些数据

  select * from dbo.RequisitionTable 
  where RequestorID = '$ID'
  and RequestorDepartmentID in ($req_dep)
  and IsProcessedToHire=0 
  and IsHold = 0
  and IsRejected = 0
但它总是会出现错误
“数组到字符串的转换”
。在这种情况下如何使用数组

谢谢

为什么不使用?你可以通过

$conds = [
   "RequestorID" => $ID,
   "IsProcessedToHire" => 0,
   "IsHold" => 0,
   "IsRejected" => 0  
];

$result = $this->db->where($conds)->where_in("RequestorDepartmentID", $req_dep)->get("RequisitionTable")->result_array();
您的查询:

select * from dbo.RequisitionTable 
where RequestorID = '$ID'
and RequestorDepartmentID in ($req_dep)
and IsProcessedToHire=0 
and IsHold = 0
and IsRejected = 0
可以很容易地转换为CodeIgniter的查询生成器,如下所示:

$this->db->select('*');
$this->db->from('dbo.RequisitionTable');
$this->db->where('RequestorID', $ID);
$this->db->where_in('RequestorDepartmentID', $req_dep);
$this->db->where('IsProcessedToHire', 0);
$this->db->where('IsHold', 0);
$this->db->where('IsRejected', 0);

上面假设$ID和$req_dep被传递给模型,后者是一个数组,或者更好地使用codeigniter的活动记录并使用
$this->db->where_in()
这是否回答了您的问题@凯文的想法对我有帮助