我正在尝试按ID批更新表
这是我的模型
public function update_batch_studentextend_by_studentID($data, $id = NULL) {
$this->db->update_batch($this->_table_name, $data, "studentID => $id");
return $id;
}
但它显示了这个错误
A Database Error Occurred
One or more rows submitted for batch updating is missing the specified index.
Filename: models/Studentextend_m.php
Line Number: 41
控制器:
$post = $this->input->post();
for($i=0; $i < count($post['subject']); $i++) {
$studentExtendArray[] = array(
'studentID' => $studentID,
'subject' => $post['subject'][$i],
'subjectng' => $post['subjectng'][$i],
'subjectlg' => $post['subjectlg'][$i],
'subjectcre' => $post['subjectcre'][$i],
);
$this->db->update_batch('studentextend', $studentExtendArray, 'studentID');
数组输出:
Array (
[0] => Array
(
[studentID] => 97
[subject] =>
[subjectng] => 115
[subjectlg] => A+
[subjectcre] => 7.0
)
[1] => Array
(
[studentID] => 97
[subject] =>
[subjectng] => 110
[subjectlg] => B-
[subjectcre] => 7.0
)
[2] => Array
(
[studentID] => 97
[subject] =>
[subjectng] => 90
[subjectlg] => C-
[subjectcre] => 8.0
) )
我正在尝试做的是更新多行关于“studentID”列。
数组输出是正确的,除了StudentID之外,每一行都有不同的值,因为这是我试图更新的信息。
1条答案
按热度按时间ruyhziif1#
所以你的函数不需要传递id,因为它在$data中,所以如果一切正常,你可以从$data中得到你已经拥有的id。