1 回答
TA贡献1876条经验 获得超6个赞
如果您只想对ramt[]具有非空值的输入进行更新,您可以为每个输入文本名称分配一个键,以便稍后识别它:
<table class="table table-bordered table-striped table-xxs" id="tb3">
<thead>
<tr>
<th>Loan No</th>
<th>Party Name</th>
<th>Coll.Amt</th>
<th>Rep Amt</th>
</tr>
</thead>
<tbody>
<?php
//echo '<pre>';print_r($result2);exit();
if(!empty($query)){
foreach($query as $key => $row){ // added $key as index
?>
<tr >
<td ><input style="width:50px" type="text" class="form-control input-xs" name="Sno[<?php echo $key ?>]" id="Sno" value="<?=$row['loanno'];?>"></td>
<td> <input style="width:180px" type="text" class="form-control input-xs" name="name[<?php echo $key ?>]" id="Amount" value="<?=$row['pname'];?>"></td>
<td ><input style="width:80px" type="text" class="form-control input-xs amt" name="Amount[<?php echo $key ?>]" id="Bankname" value="<?=$row['collection_amt'];?>"></td>
<td ><input style="width:80px" type="text" class="form-control input-xs ramt" name="ramt[<?php echo $key ?>]" id="Chqamt" value="<?=$row['receive_amt'];?>" autofocus></td>
</tr>
<?php
}
}?>
</tbody>
</table>
并过滤您的batchinsert()函数的输入数据:
public function batchinsert($data){
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['repname'];
$LDate = $this->input->post('CDate');
$date = str_replace('/', '-', $LDate);
$newDate = date("Y-m-d", strtotime($date));
$lno = $this->input->post("Sno");
$ramt = $this->input->post("ramt"); // added ramt input variable
$count = count($data['Sno']);
$updateArray = array();
for($x = 0; $x < sizeof($lno); $x++){
if (!empty($ramt[$x])) { // this will only insert data on loanno which have non-empty ramt values
$updateArray[] = array(
'loanno' => $lno[$x],
'receive_amt'=> $ramt[$x]
);
}
}
$this->db->where('collection_date',$newDate);
$this->db->update_batch('collection',$updateArray,'loanno');
// $this->db->insert_batch('test', $entries2);
redirect('Collection_Entry','refresh');
}
这只会遍历非空ramt[]输入,然后只更新动态loanno值和静态collection_date值。
// Example query output :
// UPDATE `collection`
// SET
// `receive_amt` =
// CASE
// WHEN `loanno` = '1' THEN 1
// WHEN `loanno` = '3' THEN 2
// WHEN `loanno` = '6' THEN 3
// WHEN `loanno` = '17' THEN 4
// ELSE `receive_amt`
// END
// WHERE `collection_date` = '2019/01/09' AND `loanno` IN ('1','3','6','17')
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报