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.
function deleteuser(){
$this->load->model('users');
$employees['staff'] = $this->users->getStaff();
$this->load->view('deleteuser', $employees);
}
In the deleteuser view, there's a checkbox type input generated from the array. The form action calls on a function called remove.
<form action="remove" method = "post">
<?php foreach($staff as $row): ?>
<div class="checkbox">
<label>
<input type="checkbox" name="delete[]" value="<?php echo $row->id ?>" />
<?php echo $row->lastName . ", " . $row->firstName; ?>
<br />
</label>
<?php endforeach; ?>
<br />
<br />
<input type="submit" name = "remove" value = "Delete" class = "btn btn-danger btn-lg pull-left" />
</div>
The remove function grabs the delete array from the input and passes it to a model function called deleteUser.
function remove(){
$data = $this->input->post('delete');
$this->users->deleteUser($data);
}
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.
function deleteUser($data)
{
if ($data) {
for ($i = 0; $i <= count($data); $i++)
{
$this->db->where('id', $data[$i]);
$this->db->delete('users');
}
}
}