MySQL Query Question (I guess it's something easy)

Discussion in 'PHP' started by Shadow, Mar 16, 2006.

  1. #1
    Is there a way to know the index (auto-increasing) of the last inserted row into a table in MySQL?

    What I'm trying to do:

    
    $sql = 'insert into mytable set product="'.$i.'", price="'.$j.'"';
    $DB->query($sql);
    
    echo 'You have added '. $i .' at a price of '. $j .' and the id '. ???? .' into your table.
    
    PHP:
    Counting the rows won't work for me.

    :eek:
     
    Shadow, Mar 16, 2006 IP
  2. Dejavu

    Dejavu Peon

    Messages:
    916
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In php:
    mysql_insert_id()
     
    Dejavu, Mar 16, 2006 IP
    Shadow and sarahk like this.
  3. Shadow

    Shadow Peon

    Messages:
    191
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Exactly, Thanks a lot :D
     
    Shadow, Mar 16, 2006 IP