in my view:
<form method="post" action="<?php echo base_url(); ?>Data/Penilaian/Selected">
<table class="table datatable-responsive" id="example">
<thead>
<tr>
<th><button class="btn btn-info">Submit</button></th>
<th>No</th>
<th>Kendaraan</th>
<th>Plat Nomor</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php
$no=1;
if(!empty($getsifat)) {
foreach ($getsifat as $kr_key => $kendaraan) { ?>
<tr>
<td>
<?php foreach ($kendaraan['sub']['count'] as $data) { ?>
<input type="checkbox" name="id_kendaraan[]" value="<?php echo $kendaraan['id_kendaraan'] ?>">
<input type="hidden" name="total[]" value="<?php echo $data['total'] ?>" > //this my problem
<?php } ?>
</td>
<td><?php echo $no ?> </td>
<td><?php echo $kendaraan['nama'] ?> </td>
<td><?php echo $kendaraan['platno'] ?></td>
<?php
foreach ($kendaraan['sub']['count'] as $data) { ?>
<!-- <input type="hidden" name="total[]" value="<?php echo $data['total'] ?>"> -->
<td><?php echo $data['total'] ?></td>
<?php } ?>
</tr>
<?php
$no++;
}
}
?>
</tbody>
</table>
</form>
in view i want to insert $id_kendaraan
and $total
value
this my controller:
function Selected(){
$id_kendaraan = $this->input->post('id_kendaraan');
$total = $this->input->post('total');
$data = array();
for ( $i = 0; $i < count( $id_kendaraan ); $i++ ) {
$data = array(
'id_kendaraan' => $id_kendaraan[$i],
'total' => $total[$i]
);
$this->PenilaianModel->TambahSelected($id_kendaraan, $data);
}
redirect('Data/Penilaian', 'refresh');
}
my model:
function TambahSelected($id_kendaraan, $data)
{
$this->db->where('id_kendaraan', $id_kendaraan);
$this->db->insert('tb_ranking', $data);
}
i want to insert $id_kendaraan and $total to my db but if i try this code: examle in view:
id kendaraan value = 1, total value = 20
id kendaraan value = 2, total value = 35
id kendaraan value = 3, total value = 44
if i checked $id_kendaraan 2 and press submit, in my databases data $id_kendaraan value = 2, $total value = 20, is not correct... in my db this data should be $id_kendaraan value = 2, $total value = 35
and if i try checked $id_kendaraan 3 and press submit, in my databases data $id_kendaraan value = 3, $total value = 20, is not correct... in my db this data should be $id_kendaraan value = 3, $total value = 44
and if i try checked $id_kendaraan 2,3 and press submit, in my databases data $id_kendaraan value = 2, $total value = 20 and $id_kendaraan value = 3, total value = 35, is not correct... in my db this data should be $id_kendaraan value = 2, $total value = 35 and $id_kendaraan value = 3, $total value = 44
thx for your help
Aucun commentaire:
Enregistrer un commentaire