当输入2个值collecting_id属性和2个值nama_driver属性,并在数据库中成功输入2行,
但是如果输入 2个值collect_id和 1 个值nama_driver,那么只有 1 行输入到数据库中。
如果我输入 2 个或更多collecting_id 和1 个nama_driver,数据库中只有1 行。我希望数据库中有 2 行或更多行具有相同的 nama_driver 值
这是我的控制器:
$collecting_id = $this->input->post('collecting_id');
$nama_driver = $this->input->post('nama_driver');
$data = array();
for ($i = 0; $i < count($collecting_id); $i++) {
$data[] = array(
'nama_driver' => $nama_driver[$i],
'collecting_id' => $collecting_id[$i]
);
}
$this->db->update_batch('process', $data, 'collecting_id');
{
$this->session->set_flashdata('msg','<strong>Data Deliveries Berhasil Diupdate.');
redirect('delivery/deliver_list');
}
这是我的观点:
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group">
<label>Paket</label>
<select class="js-example-basic-multiple form-control" name="collecting_id[]" multiple="multiple">
<?php
if(@$paket_incoming) :
foreach ($paket_incoming as $row) :
?>
<option value="<?php echo $row->collecting_id; ?>"><?php echo $row->collecting_id; ?></option>
<?php
endforeach;
endif;
?>
</select>
</div></div>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group">
<label>Nama Driver</label>
<select class="js-example-basic-multiple form-control" name="nama_driver[]" multiple="multiple">
<?php
if(@$driver) :
foreach ($driver as $row) :
?>
<option value="<?php echo $row->nama; ?>"><?php echo $row->nama; ?></option>
<?php
endforeach;
endif;
?>
</select>
</div></div>
<div class="col-md-12">
<center><button type="submit" class="btn btn-primary">Simpan</button>
<a href="<?php echo base_url();?>delivery/delivery_list" class="btn btn-default">Batal</a></center>
</div></div>