Flattr this!

Sometimes you need the ID just before it is generated. Here is a way to do that

$result=mysql_query(“SHOW TABLE STATUS LIKE ‘tablename’ “);

if($result & mysql_num_rows($result))

{

$row=mysql_fetch_assoc($result);

$next_id=$row[‘Auto_increment’];

}

else

{

die(“error”);

}