我正在尝试按ID批更新表
我的控制器:
if(customCompute($this->data['student'])) {
$studentextendID = $this->data['student']->studentextendID;
$this->data['students'] = $this->studentextend_m->get_studentextend(array('studentextendID' => $studentextendID));
} else {
$this->data['students'] = [];
}
$post = $this->input->post();
for($i=0; $i < count($post['subject']); $i++) {
$studentExtendArray[] = array(
'studentextendID' => $studentextendID,
'studentID' => $studentID,
'subject' => $post['subject'][$i],
'subjectng' => $post['subjectng'][$i],
'subjectlg' => $post['subjectlg'][$i],
'subjectcre' => $post['subjectcre'][$i],
);
$this->db->update_batch('studentextend', $studentExtendArray, 'studentextendID');
}
我的模型
function get_studentextend($array=NULL, $signal=FALSE) {
$query = parent::get($array, $signal);
return $query;
}
数组输出:
Array (
[0] => Array
(
[studentextendID] => 143
[studentID] => 97
[subject] =>
[subjectng] => 5235
[subjectlg] => 5231
[subjectcre] => 523155
)
[1] => Array
(
[studentextendID] => 143
[studentID] => 97
[subject] =>
[subjectng] => 2
[subjectlg] => 99
[subjectcre] => 3
) )
如您所见,'studentextendID'在两个数组上都是重复的,但它应该是动态取得的,例如:143和144,因为表中有两行具有相同的'studentID'
2条答案
按热度按时间2wnc66cl1#
您可以尝试更改模型
ig9co6j12#
您没有在for循环中传递$studentextendID。您需要在for循环中传递它。
同时请验证$this-〉data ['student']。