我在输入车队ID和多个检查单元ID中有表格。但是在一个日期中只需使用一个unit_id。
我检查此代码但数据无法插入。
$fleet = $this->input->post('id_fleet');
$unit_id = $this->input->post('unit_id');
$records = array();
for ($i=0; $i < count($unit_id) ; $i++) {
$records[] = array('id_fleet' => $fleet,
'unit_id' => $unit_id[$i]);
}
$query = $this->database_three->query("select count(id_fleet_member) as unit from fleet_member where id_fleet = '$fleet' AND unit_id = '$unit_id' group by fleet_member.id_fleet");
$ans = $query->row();
$check = $this->database_three->query("select fleet.fleet_status, fleet_member.unit_id from fleet Left join fleet_member
on fleet.id_fleet=fleet_member.id_fleet AND fleet_member.unit_id = '$unit_id' AND fleet.fleet_status = '$id_fleet'");
if ($ans->unit > 0) {
$this->session->set_flashdata('message', generateErrorMessage('Data Fleet ID Sudah Digunakan'));
redirect(site_url('fleet_member'));
} else {
if ($check == FALSE) {
foreach ($records as $data) {
$query = "insert into fleet_member (id_fleet, unit_id) values ('".$data['id_fleet']."','".$data['unit_id']."')";
$this->database_three->query($query);
}
$this->session->set_flashdata('message', generateSuccessMessage('Data berhasil ditambah'));
redirect(site_url('fleet_member'));
} else {
$this->session->set_flashdata('message', generateErrorMessage('Data Unit ID Sudah Digunakan'));
redirect(site_url('fleet_member'));
}
}
你能告诉我如何解决这个问题吗?
谢谢,