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.
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');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.