How to get the Next Auto Increment number in Mysql

Discussion in 'PHP' started by selfspirit50, Oct 14, 2006.

  1. #1
    Dear Friends.

    I want to get the How to get the Next Auto Increment number in Mysql using PHP code ?

    can i get the Next Auto Increment number in Mysql Usiing PHP code??

    Please help me
     
    selfspirit50, Oct 14, 2006 IP
  2. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    $r = mysql_query("SHOW TABLE STATUS LIKE 'table_name' ");
    $row = mysql_fetch_array($r);
    $Auto_increment = $row['Auto_increment'];
    mysql_free_result($r);
    PHP:
     
    harsh789, Oct 14, 2006 IP
  3. coolsaint

    coolsaint Banned

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you harsh, That's a cool Tip.
     
    coolsaint, Oct 19, 2006 IP
  4. marcvb

    marcvb Peon

    Messages:
    191
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you just inserted a row, you may use mysql_insert_id which basically gets the id generated from the previous insert.

    
    mysql_query("INSERT INTO mytable (id,product) values ('','item')");
    $iLastID = mysql_insert_id();
    
    PHP:
    Marc
     
    marcvb, Oct 19, 2006 IP