Welcome Guest, Not a member yet? Register   Sign In
anchor() function problem...
#5

[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 Wink


Messages In This Thread
anchor() function problem... - by El Forum - 11-13-2008, 07:48 AM
anchor() function problem... - by El Forum - 11-13-2008, 07:56 AM
anchor() function problem... - by El Forum - 11-13-2008, 08:01 AM
anchor() function problem... - by El Forum - 11-13-2008, 08:19 AM
anchor() function problem... - by El Forum - 11-13-2008, 08:22 AM
anchor() function problem... - by El Forum - 11-13-2008, 08:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB