Credit Cards - Debt Consolidation Loans - Bad Credit Mortgages - Remortgages - Debt Help

PDA

View Full Version : How to get the Next Auto Increment number in Mysql


selfspirit50
Oct 14th 2006, 4:16 am
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

harsh789
Oct 14th 2006, 11:06 am
$r = mysql_query("SHOW TABLE STATUS LIKE 'table_name' ");
$row = mysql_fetch_array($r);
$Auto_increment = $row['Auto_increment'];
mysql_free_result($r);

coolsaint
Oct 19th 2006, 2:30 am
Thank you harsh, That's a cool Tip.

marcvb
Oct 19th 2006, 5:52 am
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();


Marc