[英]How to update multiple rows in codeigniter cart
我正在使用codeigniter購物車來存儲多行。 這是一個預訂系統站點。
這是我檢索購物車的代碼:
<?php if ($cart = $this->cart->contents()): ?>
<table class="booking">
<tr>
<td>#</td>
<td>Room Type</td>
<td>Check In</td>
<td>Checkout</td>
<td>Nights</td>
<td align="right">Price/Night</td>
<td width="10">Rooms</td>
<td align="right">Amount</td>
<td>Options</td>
</tr>
<?php $grand_total = 0; $i = 0; ?>
<?php foreach ($cart as $item): ?>
<tr bgcolor="#FFFFFF">
<td><?php echo $i+1; ?></td>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['checkin']; ?></td>
<td><?php echo $item['checkout']; ?></td>
<td align="center"><?php echo $item['nights']; ?></td>
<td align="right"><?php echo number_format($item['subtotal'],2); ?></td>
<td><input type="text" name="booking<?php echo $item['id'] ?>" value="<?php echo $item['qty'] ?>" maxlength="3" size="1" style="text-align: right" /></td>
<?php $amount = $item['subtotal'] * $item['qty']; ?>
<?php $grand_total = $grand_total + $amount; ?>
<td align="right"><?php echo number_format($amount,2) ?></td>
<td><?php echo anchor('bookings/remove/'.$item['rowid'],'Cancel'); ?></td>
<?php endforeach; ?>
</tr>
<tr>
<td colspan="2"><b>Order Total: <?php echo number_format($grand_total,2); ?></b></td>
<td colspan="7" align="right">
<input type="button" value="Clear Cart" onclick="clear_cart()">
<input type="button" value="Update Cart" onclick="update_cart()">
<?php
/*if(isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) <> '')) {
$location='booking_checkout.php';
}else{
$location='billing_info.php';
}*/
?>
<input type="button" value="Place Order" onclick="window.location='<?php //echo $location; ?>'"></td>
</tr>
</table>
<?php endif; ?>
clear_cart()
函數可與以下代碼配合使用:
<script>
function clear_cart() {
var result = confirm('Are you sure want to clear all bookings?');
if(result) {
window.location = "http://localhost/reservation/bookings/remove/all";
}else{
return false; // cancel button
}
}
</script>
這是我控制器中的remove函數:
function remove($rowid) {
if ($rowid=="all"){
$this->cart->destroy();
}else{
$data = array(
'rowid' => $rowid,
'qty' => 0
);
$this->cart->update($data);
}
redirect('bookings');
}
但是,例如,如果我有多於1行,我不知道如何更新購物車。 這里重要的是更新購物車中的房間數量(即數量)。
您可以使用多維數組
$data = array(
array(
'rowid' => 'b99c',
'qty' => 3
),
array(
'rowid' => 'xw82',
'qty' => 4
),
array(
'rowid' => 'fh4k',
'qty' => 2
)
);
$this->cart->update($data);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.