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

[eluser]XssLab[/eluser]
Hello,

sorry but I have a simple problem with anchor function....

an example:

Code:
<?= anchor('users/delete/', 'delete'); ?>

I need to append ID user to delete/

and... I try with:

Code:
<?= anchor('users/delete/'".$row->id."', 'delete'); ?>

but, the HTML output... is without ID!

Where is the problem?
#2

[eluser]rogierb[/eluser]
What's up with the quotes?
Code:
<?= anchor('users/delete/'".$row->id."', 'delete'); ?>

Try
Code:
<?= anchor('users/delete/'.$row->id, 'delete'); ?>

And check if $row->id has a value Smile
#3

[eluser]XssLab[/eluser]
[quote author="rogierb" date="1226606196"]What's up with the quotes?
Code:
<?= anchor('users/delete/'".$row->id."', 'delete'); ?>

Try
Code:
<?= anchor('users/delete/'.$row->id, 'delete'); ?>

And check if $row->id has a value Smile[/quote]

Mumble, you are right!

This is a foreach right code:

Quote:foreach($query->result() as $ker => $value)
{
anchor('/edit/'.$value->id, 'edit');
}

Smile

Thanks !
#4

[eluser]JoostV[/eluser]
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;
    }
}
#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
#6

[eluser]JoostV[/eluser]
;-P




Theme © iAndrew 2016 - Forum software by © MyBB