Welcome Guest, Not a member yet? Register   Sign In
Return last inserted ID
#3

[eluser]NateL[/eluser]
Alright,

my controller sends the posted data to the model, like so:

Code:
function add()
{
$this->addressbook_model->add_new_address($_POST);
}

My model processes that data and sticks it in the database:

Code:
function add_new_address()
{
    $data = array(
        'name'      => $this->input->post('newname'),
        'email'     => $this->input->post('newemail')

    );
        
    $this->db->escape($data);
    $this->db->insert('addressbook', $data);
    $data['lastid'] = $this->db->insert_id();
    return $data;
}

As you can see, the array $data contains name and email - but after the query, it contains a third slot called 'lastid' with an integer (this works...tested it), and returns the entire $data array to my controller....

Now, how do I access that returned data? If I just use $data['lastid'] in my controller, it gives me an error.


Messages In This Thread
Return last inserted ID - by El Forum - 07-26-2009, 12:46 PM
Return last inserted ID - by El Forum - 07-26-2009, 01:15 PM
Return last inserted ID - by El Forum - 07-26-2009, 01:39 PM
Return last inserted ID - by El Forum - 07-26-2009, 02:29 PM
Return last inserted ID - by El Forum - 07-26-2009, 04:30 PM
Return last inserted ID - by El Forum - 07-27-2009, 08:54 AM
Return last inserted ID - by El Forum - 07-27-2009, 09:15 AM
Return last inserted ID - by El Forum - 07-27-2009, 09:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB