title: CodeIgniter Active Record Delete Multiple Records At Once
body: <p>This is one of my controller functions. It grabs all the rows from a database table called 'users' and puts it into an array. It then loads a view called 'deleteuser' with the array data passed through.</p>
  
  <pre><code>function deleteuser(){
  
  
  
      $this-&gt;load-&gt;model('users');
      $employees['staff'] = $this-&gt;users-&gt;getStaff();
      $this-&gt;load-&gt;view('deleteuser', $employees);
  }
  </code></pre>
  
  <p>In the deleteuser view, there's a checkbox type input generated from the array. The form action calls on a function called remove.</p>
  
  <pre><code>&lt;form action="remove" method = "post"&gt;
  
  &lt;?php foreach($staff as $row): ?&gt;
  &lt;div class="checkbox"&gt;
          &lt;label&gt;
          &lt;input type="checkbox" name="delete[]" value="&lt;?php echo $row-&gt;id ?&gt;" /&gt;
          &lt;?php echo $row-&gt;lastName . ", " . $row-&gt;firstName; ?&gt;
          &lt;br /&gt;
          &lt;/label&gt; 
  
          &lt;?php endforeach; ?&gt;
          &lt;br /&gt; 
          &lt;br /&gt;
          &lt;input type="submit" name = "remove" value = "Delete" class = "btn btn-danger btn-lg pull-left" /&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>The remove function grabs the delete array from the input and passes it to a model function called deleteUser.</p>
  
  <pre><code>function remove(){
      $data = $this-&gt;input-&gt;post('delete');
  
      $this-&gt;users-&gt;deleteUser($data);
  
  }
  </code></pre>
  
  <p>Now this is where I'm running into some trouble. Below is the model function for deleteUser, but it's giving me an undefined offset: 1 error. Any help would be appreciated.</p>
  
  <pre><code>function deleteUser($data)
  {
      if ($data) {
          for ($i = 0; $i &lt;= count($data); $i++)
          {
          $this-&gt;db-&gt;where('id', $data[$i]);
          $this-&gt;db-&gt;delete('users');
          }
      }
  }
  </code></pre>