我正在使用codeigniter,尝试在where子句中使用数组,并仅返回那些与数组匹配的id。
由表格提交:
$arrTID = $this->input->post('Present');
print_r($arrTID);
输出:
Array(
[0]=>FMM003
[1]=>30089
[2]=>30097
)
在foreach中使用时:
foreach($arrTID as $key=>$ID){
print_r($ID);
}
输出:FMM0033008930097
查询:
$query = $this->db->query("select TraineeID from tbl_attendance_processed where TraineeID IN $ID and attnDate='$atnDate'");
$res=$query->result_array();
我实际上需要该查询返回与此查询匹配的数组中的ID。怎么做到这个?
答案 0 :(得分:4)
$arrTID = $this->input->post('Present');
$atnDate = $this->input->post('atnDate');
$this->db->select('TraineeID');
$this->db->where_in('TraineeID', $arrTID);
$this->db->where('attnDate', $atnDate);
$query = $this->db->get('tbl_attendance_processed');
// and fetch result
$res = $query->result(); // as object
$res = $query->result_array(); // as array
并了解此http://www.codeigniter.com/userguide2/database/active_record.html
答案 1 :(得分:0)
$array_check = array(10,11,12,13);
$name = "Raj Shekhar";
$this->db->select('*');
$this->db->where_in('id', $array_check);
$this->db->where('name', $name);
$query = $this->db->get('table_name');
// return result as array
return $query->result_array();