2012-08-17 2 views
0

여러 행을 저장하는 데 codeigniter 카트를 사용하고 있습니다. 이것은 예약 시스템 사이트입니다.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> 

그리고 이것은 내 컨트롤러에서 제거 기능입니다 :

function remove($rowid) { 
    if ($rowid=="all"){ 
     $this->cart->destroy(); 
    }else{ 
     $data = array(
      'rowid' => $rowid, 
      'qty'  => 0 
     ); 

     $this->cart->update($data); 
    } 

    redirect('bookings'); 
} 

여기에 카트를 검색하기 위해 내 코드입니다

하지만 예를 들어 mor가있는 경우 카트를 업데이트하는 방법을 모르겠습니다. 1 행 이상. 여기서 중요한 것은 장바구니의 객실 수 (예 : 수량)를 업데이트하는 것입니다.

+0

사용할 수 있습니다 [당신이 시도 무엇?] (http://whathaveyoutried.com) – orourkek

+0

난 당신이 내가 시도 무엇보다 볼 수 있다고 생각합니다. lol – jaypabs

+0

당신이 원하는 것을하려고 시도하는 코드를 게시하지 않았기 때문에 * "나는 1 행을 어떻게 처리하는지 알았습니다. 여러 행에 대한 코드를 줄 수 있습니까? "* – orourkek

답변

1

당신은 다차원 배열

$data = array(
    array(
      'rowid' => 'b99c', 
      'qty'  => 3 
     ), 
    array(
      'rowid' => 'xw82', 
      'qty'  => 4 
     ), 
    array(
      'rowid' => 'fh4k', 
      'qty'  => 2 
     ) 
); 

$this->cart->update($data); 
관련 문제