【发布时间】:2022-06-23 15:28:11
【问题描述】:
我正在尝试通过 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'
【问题讨论】:
-
我们可能需要看到你的完整函数而不是 if 部分,你从哪里得到 var
$studentID?您也可以使用以下行强制studentExtendID:$studentextendID = $this->data['student']->studentextendID; -
查看 studentID 是没有用的,因为它已经工作正常,并且从表中获取了 studentid。另外,我真的不明白你所说的强制studentextendID是什么意思?
-
您使用的是什么版本的 Codeigniter?您似乎在滥用 Stack Overflow 问题标签(“codeigniter-3”和“codeigniter-4”)。
-
我的错,我正在使用 CI 3
标签: php codeigniter codeigniter-3