title: Codeigniter - Batch Update with Multiple Where Conditions
body: <p>For starters, the Codeigniter documentation on update_batch does not exist. kenjis was kind enough to provide some documentation and submit it to the repository. Hopefully they pull it soon. </p>
  
  <p>Does anyone know how to add multiple where conditions to Codeigniters update_batch command?</p>
  
  <p><strong>My Desired Use:</strong></p>
  
  <pre><code>$where = array(
      'title',
      'name'
  ); 
  
  $this-&gt;db-&gt;update_batch('mytable', $data, $where);
  </code></pre>
  
  <p>When I tried this code I got the follow error:</p>
  
  <pre><code>A Database Error Occurred
  One or more rows submitted for batch updating is missing the specified index.
  
  Filename: C:\wamp\www\wheel\system\database\DB_active_rec.php
  
  Line Number: 1451
  </code></pre>
  
  <hr>
  
  <p><strong>Update Batch Documentation by kenjis:</strong></p>
  
  <pre><code>$this-&gt;db-&gt;update_batch();
  </code></pre>
  
  <p>Generates an update string based on the data you supply, and runs the query. You can either pass an <strong>array</strong> or an <strong>object</strong> to the function. Here is an example using an array:</p>
  
  <pre><code>$data = array(
      array(
          'title' =&gt; 'My title' ,
          'name' =&gt; 'My Name 2' ,
          'date' =&gt; 'My date 2'
      ),
      array(
          'title' =&gt; 'Another title' ,
          'name' =&gt; 'Another Name 2' ,
          'date' =&gt; 'Another date 2'
      )
  );
  
  $this-&gt;db-&gt;update_batch('mytable', $data, 'title');
  // Produces: 
  // UPDATE `mytable` SET `name` = CASE
  // WHEN `title` = 'My title' THEN 'My Name 2'
  // WHEN `title` = 'Another title' THEN 'Another Name 2'
  // ELSE `name` END,
  // `date` = CASE 
  // WHEN `title` = 'My title' THEN 'My date 2'
  // WHEN `title` = 'Another title' THEN 'Another date 2'
  // ELSE `date` END
  // WHERE `title` IN ('My title','Another title')
  </code></pre>
  
  <p>The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.</p>
  
  <h2>Sources:</h2>
  
  <ul>
  <li>kenjis's documentation update:
  <a href="https://bitbucket.org/kenjis/ci-user-guide/changeset/3d579dd14afe">https://bitbucket.org/kenjis/ci-user-guide/changeset/3d579dd14afe</a></li>
  <li>saintnicster's pull request: <a href="https://github.com/EllisLab/CodeIgniter/pull/448">https://github.com/EllisLab/CodeIgniter/pull/448</a></li>
  </ul>