Get SQL ID

Discussion in 'MySQL' started by Weirfire, Oct 10, 2005.

  1. #1
    I have a table where I'm auto incrementing as data is inserted. I was wondering how I would obtain that ID to add data into another table at the same time where I want to use that ID?
     
    Weirfire, Oct 10, 2005 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    INSERT INTO Table 1 id = '' //auto increment

    $last_insert_id = mysql_insert_id();

    INSERT INTO Table 2 id = $last_insert_id
     
    T0PS3O, Oct 10, 2005 IP
    Weirfire likes this.
  3. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #3
    Thanks Johan. :)

    You're not just a pretty face after all :p
     
    Weirfire, Oct 10, 2005 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    :D Thanks Braveheart.

    Have you heard of this thing called Google? ;)
     
    T0PS3O, Oct 10, 2005 IP
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    I like helping out DP though. I figure that if I go to DP first then not only will I get my answer straight away but I set up all the keywords for newbies like myself trying to figure these problems out.
     
    Weirfire, Oct 10, 2005 IP