[eluser]XssLab[/eluser]
[quote author="JoostV" date="1226607548"]rogierb is right... If $row->id has no value, this statement will delete ALL the records in your table...
So, in your controller:
Code:
function delete()
{
$this->load->model('users');
if (!$this->users->delete($this->uri->segment(3))) {
show_error('This user could not be deleted.');
}
else {
echo 'User was succesfully deleted';
}
}
And in your model 'users':
Code:
function delete($user_id)
{
// Return false if user_id was not found in segment 3, or if user_id is not a number
if (!$user_id || !is_numeric($user_id)) {
return false;
}
// Delete record
$this->db->where('user_id', abs((int) $this->uri->segment(3)));
$this->db->limit(1); // delete no more than 1 record
$this->db->delete('mytable');
// Return result
if ($this->db->affected_rows() > 0) {
return true;
}
else {
return false;
}
}
[/quote]
Yeah, it's a fantastic model! Very very good