select last_insert_id();

or in php use the mysql_insert_id() eg:


$somevalue = mysql_insert_id();
print ("The last auto incremented number was: $somevalue<br>\n");

Cheers
Curtis

Paul Fine said:
> Greetinsg.
>
> If I have a table like with a column being the PK for the table and
> being an Auto Increment value, what is the best way to return this value
> to my script? It is possible that additional rows may have been added
> during the small wait.
>
> Ie.
>
> Col 1         Col 2                   Col 3
> AA#           SmallText               SmallText
>
> 123           Foo                     Bar
> 124           Good                    Guy
>
>
> So my script (PHP) for adding records to the database inserts
> NULL,"text","text" into the table but I need to echo back the # that was
> created!
>
> My thought was to maybe grab the last entry in the database before the
> insert, perform the insert and then query where the file # is greater
> than that last entry and where the text matches the columns
> appropriately.
>
> I imagine there has to be a better way!
>
> Thanks for any help!
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to