Updating Multiple Rows in Codeigniter
In your Model
following part should be
$data[] = array( $code='code' => $_POST['code'][$i], 'price' => $_POST['sell']);
replaced with
$data[] = array( 'code' => $_POST['code'][$i], 'price' => $_POST['sell']);
and to update the values you should use update_batch
instead of insert_batch
$this->db->update_batch('yourtableName', $data, 'code'); // 'code' is where key
Replace yourtableName
with your original table name and code
is being used for where
key, so you don't need to use $this->db->where('code',$code)
.
Reference: CodeIgniter.