title: How to update multiple rows in codeigniter cart
body: <p>I am using codeigniter cart to store multiple rows. This is a booking system site.</p>
  
  <p>here's my code to retrieve the cart:</p>
  
  <pre><code>&lt;?php if ($cart = $this-&gt;cart-&gt;contents()): ?&gt;
  &lt;table class="booking"&gt;
    &lt;tr&gt;
      &lt;td&gt;#&lt;/td&gt;
      &lt;td&gt;Room Type&lt;/td&gt;
      &lt;td&gt;Check In&lt;/td&gt;
      &lt;td&gt;Checkout&lt;/td&gt;
      &lt;td&gt;Nights&lt;/td&gt;
      &lt;td align="right"&gt;Price/Night&lt;/td&gt;
      &lt;td width="10"&gt;Rooms&lt;/td&gt;
      &lt;td align="right"&gt;Amount&lt;/td&gt;
      &lt;td&gt;Options&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php $grand_total = 0; $i = 0; ?&gt;
    &lt;?php foreach ($cart as $item): ?&gt;
    &lt;tr bgcolor="#FFFFFF"&gt;
      &lt;td&gt;&lt;?php echo $i+1; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $item['name']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $item['checkin']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $item['checkout']; ?&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;?php echo $item['nights']; ?&gt;&lt;/td&gt;
      &lt;td align="right"&gt;&lt;?php echo number_format($item['subtotal'],2); ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="booking&lt;?php echo $item['id'] ?&gt;" value="&lt;?php echo $item['qty'] ?&gt;" maxlength="3" size="1" style="text-align: right" /&gt;&lt;/td&gt;
      &lt;?php $amount = $item['subtotal'] * $item['qty']; ?&gt;
      &lt;?php $grand_total = $grand_total + $amount; ?&gt;
      &lt;td align="right"&gt;&lt;?php echo number_format($amount,2) ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo anchor('bookings/remove/'.$item['rowid'],'Cancel'); ?&gt;&lt;/td&gt;
      &lt;?php endforeach; ?&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan="2"&gt;&lt;b&gt;Order Total: &lt;?php echo number_format($grand_total,2); ?&gt;&lt;/b&gt;&lt;/td&gt;
      &lt;td colspan="7" align="right"&gt;
      &lt;input type="button" value="Clear Cart" onclick="clear_cart()"&gt;
      &lt;input type="button" value="Update Cart" onclick="update_cart()"&gt;
        &lt;?php
          /*if(isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) &lt;&gt; '')) {
              $location='booking_checkout.php';
          }else{
              $location='billing_info.php';
          }*/
        ?&gt;
      &lt;input type="button" value="Place Order" onclick="window.location='&lt;?php //echo $location; ?&gt;'"&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>The <code>clear_cart()</code> function works fine with the code below:</p>
  
  <pre><code>&lt;script&gt;
  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
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>And this is the remove function in my controller:</p>
  
  <pre><code>function remove($rowid) {
      if ($rowid=="all"){
          $this-&gt;cart-&gt;destroy();
      }else{
          $data = array(
              'rowid'   =&gt; $rowid,
              'qty'     =&gt; 0
          );
  
          $this-&gt;cart-&gt;update($data);
      }
  
      redirect('bookings');
  }
  </code></pre>
  
  <p>But I don't know how to update the cart if for example I have more than 1 row. The important here is to update the number of rooms (i.e. qty) in the cart.</p>