我做了多个不同数量的插入。进行交易时,我将其容纳在临时表或附加表中。但是,只存储最后一个数量
模型
public function simpan_data($data_pickup){
$this->simpan_pickup($data_pickup);
$last_key = $this->db->insert_id();
$tmp = $this->get_temporary();
foreach($tmp as $t){
$data_detail = array(
'id_pickup' => $last_key,
'id_barang' => $t->id_barang,
'qty_pickup' => $this->input->post('qty_pickup')
);
$this->db->insert('pickup_detail', $data_detail);
}
}
public function simpan_pickup($data){
$res = $this->db->insert('pickup', $data);
return $res;
}
控制器
public function add_tem_pickup(){
$idnya = $this->input->post('id_barang');
$cektmp = $this->M_pickup->cek_temporary($idnya);
if ($cektmp > 0) {
$arr=array(
'sukses' => false,
'pesan' => 'Barang sudah Pickup'
);
//alert
}else{
$data_insert = array(
'jenis' => 'PICK',
'id_barang' => $idnya
);
$this->db->insert('tem_pickup', $data_insert);
$arr = array(
'sukses' => true,
'pesan' => 'berhasil'
);
}
echo json_encode($arr);
}
public function simpan_pickup(){
$data = array(
'kd_pickup' => $this->input->post('kd_pickup'),
'id_cs' => $this->input->post('id_cs')
);
$this->M_pickup->simpan_data($data);
$this->db->delete('tem_pickup', array('jenis' => 'PICK'));
echo $this->session->set_flashdata('message','success');
redirect('backend/pickup');
}
这怎么会发生?请帮忙