title: Update array query in Codeigniter
body: <p>I am making pharmacy system using Codeigniter. I want to update stock of several items in table after purchase, below is the code what i have tried so far. </p>
  
  <p>Below is the my Controller</p>
  
  <pre><code>function add_invoice(){
  
          $customer = $this-&gt;input-&gt;post('customer');
          $date = date("Y-m-d",strtotime($this-&gt;input-&gt;post('date')));
          $grandtotal = $this-&gt;input-&gt;post('grandtotal');
          $ref = rand(1111111111,9999999999);
          $medicine = $this-&gt;input-&gt;post('medicine');
          $quantity = $this-&gt;input-&gt;post('quantity');
          $subtotal = $this-&gt;input-&gt;post('subtotal');
  
      foreach($medicine as $key=&gt;$val){
  
      $data[] = array(
              'customer' =&gt; $customer,
              'date' =&gt; $date,
              'grandtotal' =&gt; $grandtotal,
              'ref' =&gt; $ref,
              'medicine' =&gt; $val,
              'quantity' =&gt; $quantity[$key],
              'subtotal' =&gt; $subtotal[$key],
  
              );
      }
      $this-&gt;my_model-&gt;decrement_item($medicine, $quantity);
      $this-&gt;db-&gt;insert_batch('table_invoice', $data);
  
  }
  </code></pre>
  
  <p>And this is my Model below :</p>
  
  <pre><code>function decrement_item($medicine, $quantity)
  {   
      $q = "UPDATE table_med SET stock = stock - ? WHERE medicine = ?";
  
      $this-&gt;db-&gt;query($q, [$quantity, $medicine]);
  
      if($this-&gt;db-&gt;affected_rows() &gt; 0){
          return TRUE;
      }
      else{
          return FALSE;
      }
  }
  </code></pre>
  
  <p>But when I execute the code, there is a message like this
  <a href="https://i.stack.imgur.com/Up6KQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Up6KQ.png" alt="enter image description here"></a></p>
  
  <p>I know I should turn parameter to array. But I don't know how? Thanks for your help</p>