我有问题。我们如何在具有多个数据的控制器中使用update_batch()
。我想更新字段eta
中的数据(输入类型为name="tgl[]"
和lokasi_order
(输入选择选项为name="chk[]"
)
这是我的控制器/功能:
public function proses_order_action($lenght){
$input = $this->input->post(NULL, TRUE);
$get_cek = $this->input->post('chk', TRUE);// get all code 1 or 3 from each data to array
$get_tgl = $this->input->post('tgl', TRUE);
$i=0;
$data = while ($i < $lenght) {
array('lokasi_order' => $get_cek[$i], 'eta' => $get_tgl[$i]);
/*echo $get_cek[$i];
echo " ";
echo $get_tgl[$i];
echo "<br/>";*/
$i++;
};
/*echo $get_cek[0];
echo "</br>";
echo $get_tgl[0];
$data = array(
while ( $i <= $lenght) {
//array('lokasi_order' => $get_cek[$i], 'eta' => $get_tgl[$i]);
$i++;
}
);*/
$this->db->update_batch('detail_estimasi', $data);
}
这是我的观点:
<section class="content">
<div class="container-fluid">
<!-- Exportable Table -->
<div class="row clearfix">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="card">
<div class="header">
<h2>
Proses Order
</h2>
</div>
<style type="text/css">
/*hilangkan exportable dan menyisakan input search di tabel*/
.dt-buttons {
display: none;
}
</style>
<div class="body">
<div class="table-responsive">
<?php $y=1; ?>
<form method="POST" action="">
<table class="table table-bordered table-striped table-hover">
<tbody>
<tr>
<th>No.</th>
<th style="text-align: center;">Nama Barang</th>
<th style="text-align: center;">Nama Customer</th>
<th style="text-align: center;">No. Polisi</th>
<th style="text-align: center;">Kode Lokasi</th>
<th style="text-align: center;">Estimation Time Arrived</th>
</tr>
<?php
$i = 1;
$count = 0;
foreach($data as $x){
?>
<tr>
<td style="text-align: center;"><?= $i++ ?></td>
<td style="text-align: center;"><?= $x->nama_item ?></td>
<td style="text-align: center;"><?= $x->nama_lengkap ?></td>
<td style="text-align: center;"><?= $x->no_polisi ?></td>
<td style="text-align: center;">
<select class="form-control show-tick" name="chk[]">
<option value="1">Kode 1</option>
<option value="3">Kode 3</option>
</select>
</td>
<td style="text-align: center;">
<input type="date" name="tgl[]">
</td>
</tr>
<?php $count++;} ?>
</tbody>
</table>
<input type="submit" formaction="<?= base_url('partsman/proses_order_action/'.$count) ?>" name="" class="btn btn-warning waves-effect" value="Order">
</form>
</div>
</div>
</div>
</div>
</div>
<!-- #END# Exportable Table -->
<!-- Exportable Table -->
</div>
这是我的视图捕获:
我想更新我的数据。
答案 0 :(得分:0)
public function proses_order_action()
{
$input = $this->input->post(NULL, TRUE);
$get_cek = $this->input->post('chk', TRUE);
$get_tgl = $this->input->post('tgl', TRUE);
foreach($get_cek as $cek)
{
$data['lokasi_order']= $cek;
}
foreach($get_tgl as $tgl)
{
$data['eta'] =$t;
}
$this->db->update_batch('detail_estimasi', $data);
}