Script Multi Insert Dan Update Data Di Codeigniter
Hello kawan, postingan ini bukanlah postingan tutorial. Ini hanya postingan arsip doank, saya takut lupa makanya saya pribadi tulis di blog seadanya. Maaf jikalau penjelasannya tidak terlalu jelas. Untuk pembahasan ini akan saya bahas di postingan selanjutnya :) .
Insert Data
View
<div class="form-group">
<div class="input-group">
<div class="row">
<div class="col-md-6">
<input class="form-control" type="text" name="name_attribut[]" placeholder="Attribut Name" maxlength="20">
</div>
<div class="col-md-6">
<input class="form-control" type="text" name="value_attribut[]" placeholder="Value" maxlength="25">
</div>
</div>
<span class="input-group-btn">
<button class="btn btn-danger" type="button">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
</div>
</div>
Controller :
//Update data attribut
$name_attribut= $this->input->post('name_attribut');
$result = array();
foreach($name_attribut AS $key => $val){
$result[] = array(
"nama_attribut" => $_POST['name_attribut'][$key],
"value" => $_POST['value_attribut'][$key]
);
}
$this->db->insert_batch('dt_attribut', $result);
Update Data
View
<?php foreach($attribut as $att){?>
<div class="form-group">
<div class="input-group">
<div class="row">
<div class="col-md-6">
<input class="form-control" type="text" name="name_attribut[]" placeholder="Attribut Name" value="<?php echo $att->nama_attribut;?>" maxlength="20">
<input type="hidden" name="ID_att[]" value="<?php echo $att->ID;?>">
</div>
<div class="col-md-6">
<input class="form-control" type="text" name="value_attribut[]" placeholder="Value" value="<?php echo $att->value;?>" maxlength="25">
</div>
</div>
<span class="input-group-btn">
<button class="btn btn-danger" type="button">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
</div>
</div>
<?php } ?>
Controller :
//Update data attribut
$ID_att = $this->input->post('ID_att');
$result = array();
foreach($ID_att AS $key => $val){
$result[] = array(
"ID" => $ID_att[$key],
"nama_attribut" => $_POST['name_attribut'][$key],
"value" => $_POST['value_attribut'][$key]
);
}
$this->db->update_batch('dt_attribut', $result, 'ID');
Sumber http://www.kang-cahya.com
0 Response to "Script Multi Insert Dan Update Data Di Codeigniter"
Posting Komentar