Results 1 to 4 of 4

Thread: [RESOLVED] Get index of INSERT statement

  1. #1

    Thread Starter
    Hyperactive Member half flung pie's Avatar
    Join Date
    Jun 2005
    Location
    South Carolina, USA
    Posts
    317

    Resolved [RESOLVED] Get index of INSERT statement

    In php, I have a bit of code that runs
    Code:
    INSERT INTO tbl_name (stuff,things) VALUES ('23','45')
    using the mysql_query($sqlquery) function.
    The table has an additional column called "id" which is an auto incremental index.

    Is there a way to get the index of this newly added row? I need the index so I can have something in an events table that basically says "Item 2 was added 2012/2/6."

    Base 2
    Fcnncu"Nqxgu"Lguug##

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Get index of INSERT statement

    Since you're using mysql_query, you can use mysql_insert_id.

    http://php.net/manual/en/function.mysql-insert-id.php

  3. #3
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Get index of INSERT statement

    Have a look at mysql_insert_id().

    Edit: kfcSmitty slipped in before me.

  4. #4

    Thread Starter
    Hyperactive Member half flung pie's Avatar
    Join Date
    Jun 2005
    Location
    South Carolina, USA
    Posts
    317

    Re: [RESOLVED] Get index of INSERT statement

    Wow, I can't believe I've never come across that function. Thank you both!

    Base 2
    Fcnncu"Nqxgu"Lguug##

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width