我有某个学期的上传结果表。我收集了某个学期的所有科目和学生名单。但我的问题是我无法将结果插入数据库。只插入一行,
控制器
$data=array();
for($i=0;$i<count($_POST['Number']);$i++){
if($_POST['Number'][$i] != ''){
$data=array(
'Id'=>$_POST['id'][$i],
'Dept'=>$_POST['Dept'][$i],
'SubjectCode'=>$_POST['sCode'][$i],
'SubjectName'=>$_POST['sName'][$i],
'Semister'=>$_POST['Semister'][$i],
'MidNumber'=>$_POST['Number'][$i]
);
$this->load->model('Upload_Result_model');
$this->Upload_Result_model->upload_midResult($data);
}
}
形式:
<table>
<tr>
<th>Student ID</th>
<?php foreach($subjects as $s):?>
<th><?php echo $s->subjectName; echo "<br>"; echo "(".$s->subjectCode.")"; ?></th>
<?php foreach($student as $st):?>
<input type='hidden' id='id[]' name='id[]' value='<?php echo $st->Id;?>'>
<?php endforeach;?>
<input type='hidden' name='Dept[]' id='Dept[]' value=<?php echo $Dept;?>>
<input type='hidden' name='Semister[]' id='Semister[]' value=<?php echo $Semister;?>>
<input type='hidden' id='sCode[]' name='sCode[]' value='<?php echo $s->subjectCode?>'>
<input type='hidden' id='sName[]' name='sName[]' value='<?php echo $s->subjectName?>'>
<?php endforeach;?>
</tr>
<?php foreach($student as $st):?>
<tr>
<td><?php echo $st->Id?></td>
<?php for($i=0;$i<count($subjects);$i++):?>
<td><input type='text' size='7' id='Number[]' name='Number[]'/></td>
<?php endfor;?>
</tr>
如果有人解决这个问题,对我会有很大帮助