我正在使用复选框发送已选中的电子邮件。电子邮件发送后,sendinvoice状态更改为Y。当我选中1个复选框时,一切正常。但当我选中多个复选框时,该功能仅更新1个复选框
如何让它可以运行更新功能与多个复选框?
查看下面复选框和按钮的代码
<button type="button" class="btn waves-effect waves-light btn-info" id="btn-sentcitilink"> Sent Email</button>
<?php
foreach($result as $row){
?>
<form method="post" action="<?php echo base_url(); ?>cms/emailcitilink" id="sentemailcitilink">
<?php
}
?>
<table id="myTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Send Invoice </th>
<th>Booking ID</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $row){
?>
<tr>
<td>
<?php if($row['sendinvoice'] == 'N'){ ?>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="books[]" id="tableDefaultCheck/<?php echo $row['booking_id']?>" value="<?php echo $row['booking_id']?>">
<label class="custom-control-label" for="tableDefaultCheck/<?php echo $row['booking_id'] ?>"></label>
</div>
<?php } ?>
<?php if($row['sendinvoice'] == 'Y'){ ?>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="tableDefaultCheck3" checked disabled>
<label class="custom-control-label" for="tableDefaultCheck3"></label>
</div>
<?php } ?>
</td>
<td>
<div class="hover-link">
<a href="<?php echo base_url(); ?>cms/transaction/view/<?php echo $row['_id'] ?>">
<?php echo $row['booking_id'] ?>
</a>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script>
$(document).ready(function() {
$("#check-all").click(function() {
if ($(this).is(":checked"))
$(".check-item").prop("checked", true);
else // Jika checkbox all tidak diceklis
$(".check-item").prop("checked", false);
});
$("#btn-sentcitilink").click(function() {
var confirm = window.confirm("Apakah Anda mengirim email data-data ini?");
if (confirm)
$("#sentemailcitilink").submit();
});
});
</script>
控制器代码
function emailtocitilink(){
$books = $_POST['books'];
$get_trans = $this->cms_model->get_transaction_by_list_trip($tripsData);
foreach($get_trans as $row){
$arr_data = array(
'booking_id' => $row['TRANSIDMERCHANT'],
);
array_push($arr, $arr_data);
}
$data = $this->data;
$data['result'] = $arr;
$datas = array(
'SendINVOICE' => "Y"
);
$insert = $this->cms_model->update_transaction($datas, $books);
redirect(base_url().'cms/citilinktransaction/');
}
型号
function get_transaction_by_list_trip($TripUUID){
return $this->mongo_db
->where_in('TripUUID', $TripUUID)
->where(array('PAYMENTCHANNEL' => 'TESTINGCHANNEL'))
->order_by(array('transaction_date' => 'desc'))
->get('tr_transaction');
}
function update_transaction($datas, $books){
return $this->mongo_db->where_in('TRANSIDMERCHANT', $books)
->set($datas)
->update('tr_transaction',['multi' => TRUE]);
}
2条答案
按热度按时间ccgok5k51#
在模型上,它应该是
'multiple' => true
6ie5vjzr2#
使用“update_all”更新多条记录
$this-〉mongo_db-〉集合($datas,[“multi”=〉true])-〉其中(“交易商”,$books)-〉更新所有(“交易记录”);