我有一个名为$req_dep
的数组数据。这是当我var_dump()
它时的样子。
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
但它总是得到错误"Array to string conversion"
。如何在这样的条件下使用数组?
谢谢
您的查询:
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被传递给模型,而后者是一个数组
为什么不使用查询生成器类?你可以这样做,
$conds = [
"RequestorID" => $ID,
"IsProcessedToHire" => 0,
"IsHold" => 0,
"IsRejected" => 0
];
$result = $this->db->where($conds)->where_in("RequestorDepartmentID", $req_dep)->get("RequisitionTable")->result_array();