Welcome Guest, Not a member yet? Register   Sign In
Having problems with creating a CRUD..
#9

[eluser]Pascal Kriete[/eluser]
For the remove function it's pretty straight forward. For each remove link you output, you also add a url segment with the id.

So your link would be: http://www.example.com/comment/delete/5

And your code:
Code:
function delete($id = -1)
{
    $this->db->delete('usercomment', array(’id’ => $id));
}

For the edit field you use the same concept. The slug defines the id and is passed into your function as an argument.
Code:
function edit($id)
{
    $this->load->helper('form');
    
    $query = $this->db->get_where('comments', array('id' => $id));
    $data['comment'] = $query->result();

    if ( count($_POST) > 0 )
    {
         $this->db->where('id', $id);
        $this->db->update('comment', $_POST);
        redirect('');
    }
    else
    {
        $this->load->view('edit_comment', $data);
    }
}

All of the keys in the data array are converted to variables in the view so $data['comment'] becomes $comment.

View:
Code:
<?= form_open('comment/edit/'.$comment->id); ?>

<input type="text" name="comment" maxlength="20" value="<?=$comment->text ?>">

// Etc.

Obviously, you will want form validation and such, but this should get the idea across.

Hope that helps.

ps. try wrapping the code you post in [ code ] tags, it makes it a lot easier to read


Messages In This Thread
Having problems with creating a CRUD.. - by El Forum - 06-05-2008, 12:03 PM
Having problems with creating a CRUD.. - by El Forum - 06-05-2008, 12:22 PM
Having problems with creating a CRUD.. - by El Forum - 06-05-2008, 05:14 PM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:26 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:34 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:38 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 11:46 AM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 12:01 PM
Having problems with creating a CRUD.. - by El Forum - 06-06-2008, 12:16 PM
Having problems with creating a CRUD.. - by El Forum - 06-07-2008, 01:58 AM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 12:45 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 01:01 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 02:22 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 02:54 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 03:22 PM
Having problems with creating a CRUD.. - by El Forum - 06-10-2008, 03:47 PM
Having problems with creating a CRUD.. - by El Forum - 06-11-2008, 04:50 PM
Having problems with creating a CRUD.. - by El Forum - 06-11-2008, 05:57 PM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 10:09 AM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 12:33 PM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 02:52 PM
Having problems with creating a CRUD.. - by El Forum - 06-12-2008, 08:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB