Reputation: 30158
I have an array of post data ($data) in codeigniter that looks like the attached image.
And a database that looks like:
id: 3 val: 37.10119357072203
-
id: 4 val: -122.06634521484374
I want to insert the array value into the 'val' field based on the array key matching the database 'id' field. How do I do this using codeigniter's update_batch. My model is currently:
public function edit_config($data){
$this->db->update_batch('extra_config', $data,'val');
}
but I get the error:
One or more rows submitted for batch updating is missing the specified index.
Upvotes: 0
Views: 5296
Reputation: 4686
You have to prepare your data its not normal not to touch it from the incoming request..
public function edit_config($data){
$updateData = array();
foreach($data['val'] as $key=>$value) {
$updateData[] = array('id'=>$key, 'val'=>$value);
}
$this->db->update_batch('extra_config', $updateData,'id');
}
Upvotes: 1