title: codeigniter undefined offset error
body: <p>I'm currently learning cart system with CI and got some problems</p>
  
  <pre><code>A PHP Error was encountered 
  Severity: Notice
  Message: Undefined offset: 2
  Filename: models/main_model.php
  Line Number: 241
  </code></pre>
  
  <p>here's the code:</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>function update_cart(){
      $this-&gt;main_model-&gt;validate_update_cart();
      redirect('cart');
  }
  </code></pre>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>function validate_update_cart(){
  
      // Get the total number of items in cart
      $total = $this-&gt;cart-&gt;total_items();
  
      // Retrieve the posted information
      $item = $this-&gt;input-&gt;post('rowid');
      $qty = $this-&gt;input-&gt;post('qty');
  
      // Cycle true all items and update them
      for($i=0;$i &lt; $total;$i++)
      {
          // Create an array with the products rowid's and quantities. 
          $data = array(
             'rowid' =&gt; $item[$i], //this is line 241
             'qty'   =&gt; $qty[$i]
          );
  
          // Update the cart with the new information
          $this-&gt;cart-&gt;update($data);
      }
  
  }
  </code></pre>
  
  <p><strong>view:</strong></p>
  
  <pre><code>&lt;div id="main"&gt;
  &lt;?php if(!$this-&gt;cart-&gt;contents()):
      echo 'You don\'t have any items yet.';
  else:
  ?&gt;
  
  &lt;?php echo form_open('cart/update_cart'); ?&gt;
  &lt;table width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;td style="background-color:yellow;"&gt;Qty&lt;/td&gt;
              &lt;td style="background-color:yellow;"&gt;Item No/td&gt;
              &lt;td style="background-color:yellow;"&gt;Description&lt;/td&gt;
              &lt;td style="background-color:yellow;"&gt;Color&lt;/td&gt;
              &lt;td style="background-color:yellow;"&gt;Price&lt;/td&gt;
              &lt;td style="background-color:yellow;"&gt;Sub-Total&lt;/td&gt;
              &lt;td style="background-color:yellow;"&gt;Delete&lt;/td&gt;
  
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;?php $i = 1; ?&gt;
          &lt;?php foreach($this-&gt;cart-&gt;contents() as $items): ?&gt;
  
          &lt;?php echo form_hidden('rowid[]', $items['rowid']); ?&gt;
          &lt;tr &lt;?php if($i&amp;1){ echo 'class="alt"'; }?&gt;&gt;
              &lt;td&gt;
                  &lt;?php echo form_input(array('name' =&gt; 'qty[]', 'value' =&gt; $items['qty'], 'maxlength' =&gt; '3', 'size' =&gt; '5')); ?&gt;
              &lt;/td&gt;
              &lt;td&gt;&lt;a style="font-size:11px;"&gt;&lt;?php echo $items['id']?&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a style="font-size:11px;"&gt;&lt;?php echo $items['name']; ?&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a style="font-size:11px;"&gt;&lt;?php echo $items['warna']?&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a style="font-size:11px;"&gt;Rp. &lt;?php echo number_format($items['price'],0,",",".");?&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a style="font-size:11px;"&gt;Rp. &lt;?php echo number_format($items['subtotal'],0,",",".");?&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href="&lt;?= base_url();?&gt;cart/delete/&lt;?= $items['rowid'];?&gt;"&gt;&lt;img src="&lt;?= base_url();?&gt;assets/image/hapus.png"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;?php $i++; ?&gt;
          &lt;?php endforeach; ?&gt;
          &lt;tr&gt;
              &lt;td colspan="5"&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;
              &lt;td colspan="2"&gt;&lt;a align="right"&gt;&lt;?php echo $this-&gt;cart-&gt;format_number($this-&gt;cart-&gt;total()); ?&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;p&gt;&lt;?php echo "&lt;input type='submit' class='Button' value='Update'&gt;";?&gt;&lt;/p&gt;
  &lt;?php 
  echo form_close(); 
  endif;
  ?&gt;
  </code></pre>
  
  <p>edited the view, complete code.
  when i click the update button it returned error live above.
  thanks.</p>