title: update multiple rows into database using codeigniter
body: <p>i am new in codeigniter. can someone please help me to solve this. I want to display a table that contain input field so that user can insert the data and update it into database. User can change all the data in the table. I want to update multiple rows at a time, but it ends up updating only 1 row (the last row). Anyone please help me for this. Thnks. This are the following code.</p>
  
  <p>model</p>
  
  <pre><code>public function add_order_data($itemcode, $qty, $supcode, $guid)  
  {  
  
      $sql1 = "SELECT * FROM stock_count INNER JOIN stock_count_item";
      $query1 = $this-&gt;db-&gt;query($sql1);
      $num = $query1-&gt;result();
  
      for($i=0;$i&lt;count($query1);$i++){
      //data is retrive from this query
      $sql = "UPDATE
          stock_count,
          stock_count_item,
          po_ex_c
        INNER JOIN po_ex ON po_ex_c.poex_guid = po_ex.poex_guid 
        SET stock_count.posted = '1',
          stock_count_item.qty_order = '$qty[$i]',
          po_ex_c.qty_actual = '$qty[$i]'
        WHERE stock_count.TRANS_GUID = '$guid[$i]' AND
          stock_count_item.Itemcode = '$itemcode[$i]' AND
          po_ex_c.itemcode = '$itemcode[$i]' AND
          stock_count_item.TRANS_GUID = '$guid[$i]' AND
          po_ex.sup_code = '$supcode[$i]'";
      $query = $this-&gt;db-&gt;query($sql);
      }
      return $query;
  }
  </code></pre>
  
  <p>controller</p>
  
  <pre><code>function add_order()
  {
  
      $qty = $this-&gt;input-&gt;post('qty');
      $itemcode = $this-&gt;input-&gt;post('itemcode');
      $supcode = $this-&gt;input-&gt;post('supcode');
      $guid = $this-&gt;input-&gt;post('guid');
  
      if ($this-&gt;input-&gt;post('save') == "save")
      {
          $result  = $this-&gt;submit2_model-&gt;add_order_data($itemcode, $qty, $supcode, $guid);   
          if($result &gt; 0)
          {
  
              redirect("home_c/viewdata");
              echo "&lt;script&gt; alert('succesfully add');&lt;/script&gt;";
          }
          else
          {
              redirect("submit2_c/viewdata");
              echo "&lt;script&gt; alert('cannot add');&lt;/script&gt;";
          }
      }
  
  }
  </code></pre>
  
  <p>view</p>
  
  <pre><code>&lt;form class="form-inline" role="form" method="POST" id="myForm" action="&lt;?php echo site_url('submit2_c/add_order'); ?&gt;"&gt;
  
    &lt;td&gt;&lt;input type="number" name="qty[]" value="" style="text-align:center;width:80px;" max="100000"/&gt;&lt;/td&gt;
  
    &lt;td&gt;&lt;?php echo $row-&gt;SupLastPrice; ?&gt;&lt;/td&gt;
  
    &lt;td&gt;&lt;?php echo $row-&gt;SupStdPrice; ?&gt;&lt;/td&gt;
  
    &lt;td&gt;&lt;?php echo $row-&gt;ads; ?&gt;&lt;/td&gt;
  
    &lt;td&gt;&lt;?php echo $row-&gt;ams; ?&gt;&lt;/td&gt;
  
    &lt;td&gt;&lt;?php echo $row-&gt;aws; ?&gt;&lt;/td&gt;
  
    &lt;td&gt;&lt;?php echo $row-&gt;doh; ?&gt;&lt;/td&gt;
  
   &lt;/tr&gt;
  &lt;/tbody&gt;
  
  &lt;input type="" name="itemcode[]" value="&lt;?php echo $row-&gt;Itemcode; ?&gt;" style="text-align:center;width:80px;" max="100000"/&gt;
  &lt;?php
     }
  ?&gt;
  &lt;input type="" name="supcode[]" value="&lt;?php echo $_SESSION["supcode"]; ?&gt;" style="text-align:center;width:80px;" max="100000"/&gt;
  &lt;input type="" name="guid[]" value="&lt;?php echo $_SESSION["guid"]; ?&gt;" style="text-align:center;width:80px;" max="100000"/&gt;
  
  &lt;/table&gt;
  
  &lt;div class="box"&gt;
      &lt;h5&gt;ADS = &lt;b&gt;Average Daily Sales&lt;/b&gt;&lt;/h5&gt;
      &lt;h5&gt;AWS = &lt;b&gt;Average Weekly Sales&lt;/b&gt;&lt;/h5&gt;
      &lt;h5&gt;AMS = &lt;b&gt;Average Monthly Sales&lt;/b&gt;&lt;/h5&gt;
      &lt;h5&gt;DOH = &lt;b&gt;Daily On Hand&lt;/b&gt;&lt;/h5&gt;
  &lt;/div&gt;&lt;br&gt;
  
  &lt;button value="save" name="save" type="submit" class="btn btn-default btn-sm" style="margin-left: 0px;background-color:#00b359;width:70px;margin-right:8px"&gt;
      &lt;b&gt;SUBMIT&lt;/b&gt;
  &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>