从数组插入一些数据后出现问题,插入数据正常工作。但是重定向不起作用,我不理解错误,因为没有错误消息只显示空白页面,我已经尝试过并尝试过,直到它成为让我疲惫的习惯。
这是我使用的函数控制器:
public function all() {
$data = array();
$idkelas = $this->input->post('kelas');
$idabsen = $this->input->post('idabsensi');
$idabsen2 = $this->input->post('idabsen');
$id = $this->input->post('idsiswa');
$hadir = $this->input->post('hadir');
$smt = $this->input->post('semester');
$jamke = $this->input->post('jamke');
$count = count($id);
// to absensi
$this->db->query("UPDATE absensi SET jmlhadir = '$count' WHERE idabsensi = '$idabsen2'");
// to absensidetail
for($j=0; $j < (int)($count); $j++) {
$data[] = array(
'idabsensi' => $idabsen[$j],
'idsiswa' => $id[$j],
'statusabsen' => $hadir[$j],
'semester' => $smt[$j],
'jamke' => $jamke[$j]
);
}
return $this->db->insert_batch('absensidetail', $data);
redirect('absensi/absen/pilihkelas/'.$idkelas, 'refresh');
}
这是视图:
<form action="<?php echo base_url()?>absensi/absen/all" method="post">
<input type="submit" class="btn btn-info btn-large" value="ABSENT ALL" />
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>No.</th>
<th>No. Induk</th>
<th>Student Name</th>
<th>Gender</th>
<th>State</th>
<th></th>
</tr>
</thead>
<tbody>
<?php $i=0 ?>
<?php foreach($kel as $d):
$i++;
?>
<tr class="list-users">
<td><input type="hidden" name="idsiswa[]" value="<?=$d->idsiswa?>" readonly><?=$d->idsiswa?></td>
<td><input type="hidden" name="hadir[]" value="hadir" readonly><input type="hidden" name="jamke[]" value="<?=$jamke?>" readonly><input type="hidden" name="mapel" value="<?=$idmapel?>" readonly><?=$d->noinduk?></td>
<td><input type="hidden" name="kelas" value="<?=$d->kelas?>" readonly><input type="hidden" name="semester[]" value="<?=$h_getsmt->idsemester?>" readonly><?=$d->namasiswa?></td>
<td><input type="hidden" name="idabsensi[]" value="<?=$d->idabsensi?>" readonly><input type="hidden" name="idabsen" value="<?=$d->idabsensi?>" readonly><?=$d->jeniskelamin?></td><td><span class="label label-unabsent">unabsent</span></td>
<td>
<div class="btn-group">
<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">Actions <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a ><i class="icon-pencil"></i>Press Button<BR>ABSENT ALL First</a></li>
</ul>
</div>
</td></tr>
<?php endforeach ?>
</tbody>
</table>
</form>
我真的希望有人可以帮助我。 谢谢
答案 0 :(得分:1)
答案 1 :(得分:0)
从批处理插入的语句中删除return
。如果有return
,则不会转到为重定向编写的下一个语句。
像这样更新。
$this->db->insert_batch('absensidetail', $data);
redirect('absensi/absen/pilihkelas/'.$idkelas, 'refresh');