Although I am not sure. update_batch is it possible to without replacing the previous data next updated value will puts by comma separated as an array-form on the SAME FILED . I shown 2 Demo image for better understand. My Code is already running for only batch update But not for update_batch increment value without replacing previous data!
For example - For 1st time update , column field will shown like this at "t_franchise_price" column ---
For 2nd time When next update will perform , then column field "t_franchise_price" will look like this ---
My Controller is
public function batch_update() {
$sID = $this - > input - > post('test_id[]');
$sAmt = $this - > input - > post('test_priceUpdt[]');
$sOfficeId = $this - > input - > post('fran_office_id');
date_default_timezone_set('Asia/Kolkata');
$edited_test = array();
if (!empty($sID)) {
foreach($sID as $k => $v) {
$edited_test = array(
'test_id' => $sID[$k],
'test_priceUpdt' => $sAmt[$k],
'fran_office_id' => $sOfficeId,
'last_edit_date' => date('Y-m-d H:i:s', time())
);
$edited_test = json_encode($edited_test);
$postData[] = array('test_id' => $v, 't_franchise_price' => $edited_test);
}
$data['franchise_tst_pkg'] = (object) $postData;
}
#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - #
if ($this - > form_validation - > run() === true) {
$this - > franchise_price_model - > batchTestupdate($postData);
$this - > session - > set_flashdata('message', display('save_successfully'));
redirect('branch/franchise_price/create');
}
**My Model is **
public function batchTestupdate($data = [])
{
$this->db
->update_batch($this->table_test, $data , 'test_id');
}
View
<tr>
<td>
<input type="text" name="test_name[]" class="form-control" placeholder="" value="<?php echo $subject->test_name; ?>" disabled>
<input type="hidden" name="test_id[]" class="form-control" placeholder="" value="<?php echo $subject->test_id; ?>">
</td>
<td>
<input type="text" name="test_price[]" class="form-control" placeholder="" value="<?php echo $subject->test_price; ?>" disabled>
</td>
<td>
<input type="text" name="test_priceUpdt[]" class="form-control" placeholder="" value="<?php echo $subject->test_price; ?>" id="test_priceEdt">
</td>
</tr>
Appends on table field
t_franchise_price
rather than overwrite.Change:
To:
Change your model method to this: