Quote:
Originally Posted by chrishirst
SELECT MAX(idcolumn) +1 as nextid FROM table ORDER BY id ASC LIMIT 1;
OR
for MySql V 5.1.12 + you can use
SELECT LAST_INSERT_ID(idcolumn + 1) AS nextid FROM table;
Bear in mind if more than one process or user is inserting records this may not be be accurate as the auto increment on fires on the INSERT process.
|
Thanks
That's the point. Bacause it will be adding quaite a few records by diferente users at the same time. At the moment a lot of ref are recorded in duplicate and triplicate due the fact one user do not know when another is adding records.
I just did this way, but no success:
<? $sql2="SELECT LAST_INSERT_ID(id + 1) AS nextid FROM table";
$result2=mysql_db_query("database",$sql2);
$regist2=mysql_fetch_array($result2);
$ref=$regist2["id"];
?>
<? echo"$ref"; ?>
Last edited by josil; 12-17-2009 at 06:26 PM..
|