Welcome Guest, Not a member yet? Register   Sign In
Newbie Q: Show newly inserted data.
#1

[eluser]Unknown[/eluser]
Code:
function event_insert()
    {
        $this->db->insert('events', $_POST);

        redirect('events/show/1');   // I want to replace the 1 here
    }

function show()
    {
        $data['query'] = $this->db->get_where('events',array('id'=> $this->uri->segment(3) ));
        $this->load->view('events/show', $data);
    }

So I have this function that will insert a row into the database. And I want to immediately redirect the user to a page displaying the info he just submitted. Is there any easy way to do this without writing specific SQL queries?

I want to get the "id" of the row I just inserted so I can add it to the redirect link, so the show page displays the info in that row. The "id" field is the primary key that auto-increments in the in table "events".
#2

[eluser]CroNiX[/eluser]
Just get the last insert id.
redirect('events/show/' . $this->db->insert_id() );
#3

[eluser]Unknown[/eluser]
That was exactly what I was looking for, thanks so much!




Theme © iAndrew 2016 - Forum software by © MyBB