我在使用foreach循环进行更新查询时出现问题,它在右行更新,但是当我点击我的其他按钮(批准按钮)下方的按钮时,它没有在我的列批准状态和状态中插入正确的数据,但更新从最新一行获取数据,请帮助我们,谢谢!
视图:
<?php } else { foreach($getNoti as $row): $id = $row->id; $timeStat = $row->status; $approveStat = $row->ApprovalStat; ?>
<tr>
<input type="hidden" name="approval" value="<?php echo $row->ApprovalStat ?>">
<input type="hidden" name="userID" value="<?php echo $row->id ?>">
<td class="tn-ixdt"><?php echo $row->name ?></td>
<td class="tn-ixdt"><?php echo $row->status ?></td>
<td class="tn-ixdt"><?php echo $row->dateToday ?></td>
<td class="tn-ixdt"><?php echo $row->timeIn ?></td>
<td class="tn-ixdt" style="text-align:right;"><button class="approveStat" name="approveStat" value="<?php echo $row->timeId ?>"><img src="<?php echo base_url('assets/img/ico-approve.png'); ?>"></img></button><button class="deleteStat" name="deleteStat" value="<?php echo $row->timeId ?>"><img src="<?php echo base_url('assets/img/ico-delete.png'); ?>"></img></button></td>
</tr>
<?php endforeach; } ?>
控制器
elseif (isset($_POST['approveStat'])){
$userID = $this->input->post('userID');
$timeID = $this->input->post('approveStat');
$approval = $this->input->post('approval');
if ($approval == 'pendingWHome') {
$insStat = 'Work at Home';
$insApprove = 'approveWHome';
}elseif ($approval == 'pendingFWork') {
$insStat = 'Field Work';
$insApprove ='approveFWork';
}elseif ($approval == 'pendingALeave') {
$insStat = 'Authorized Leave';
$insApprove = 'approveALeave';
}elseif ($approval == 'pendingHoliday') {
$insStat = 'Non-Working Holiday';
$insApprove = 'approveHoliday';
}
$this->admin->verifyNoti($userID, $timeID, $insApprove, $insStat, $datenow);
redirect('admin/pending');
}
型号:
function verifyNoti($userID, $timeID, $insApprove, $insStat, $year_num)
{
$jd=cal_to_jd(CAL_GREGORIAN,date('m'),date('d'),date('Y'));
$today=(jddayofweek($jd,1));
//get weekday only
$dateOrder = date("Ymd");
//User for date ordering
$verify = array(
'status' => $insStat,
'ApprovalStat' => $insApprove
);
$this -> db -> where('timeId', $timeID);
$query = $this->db->update('timerecord', $verify);
}
function getNotification()
{
$this -> db -> select('users.*');
$this -> db -> select('timerecord.*');
$this -> db -> from('users');
$this -> db -> join('timerecord', 'users.id = timerecord.id', 'left');
$this -> db -> where('timerecord.ApprovalStat !=', '');
$this -> db -> where('timerecord.ApprovalStat !=', 'approveFWork');
$this -> db -> where('timerecord.ApprovalStat !=', 'approveWHome');
$this -> db -> where('timerecord.ApprovalStat !=', 'approveALeave');
$this -> db -> where('timerecord.ApprovalStat !=', 'approveHoliday');
$this -> db -> order_by('timerecord.dateOrder', 'DESC');
$query = $this -> db -> get();
return $query->result();
}
答案 0 :(得分:0)
所有按钮在行(approveStat)中的名称相同,如果您将类型设置为提交,则按钮值将在点击的位置(当前行)发布。
如果你添加一个带有数组名称的隐藏字段或复选框,你可以使用approveAll按钮(如果你想在下面这样做)
仅在php中,复选框值将发布在哪里检查 - &gt;处理它 - &gt;构建更新阵列 - &gt;赢
sort how too
aslo使用elseif的开关盒; - )