Getting the last number from an auto_increment field

Codes here !

Moderators: egami, macek, gesf

Post Reply
fredws
New php-forum User
New php-forum User
Posts: 14
Joined: Wed Jul 16, 2003 4:16 pm

Mon Mar 08, 2004 9:15 am

What is the easiest way to go about finding what the last number was in an auto_increment field?

For instance, if I have a invoice table, where the invoice number is auto_increment, right after creating an invoice, how do I find what invoice number was assigned?
User avatar
gesf
Moderator
Moderator
Posts: 1716
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Wed Mar 10, 2004 5:58 am

LAST_INSERT_ID() is what you need. Check this out:
http://www.mysql.com/doc/en/mysql_insert_id.html
Sincerely,
Gonçalo "gesf" Fontoura
fredws
New php-forum User
New php-forum User
Posts: 14
Joined: Wed Jul 16, 2003 4:16 pm

Wed Mar 10, 2004 8:35 am

Thats what I was after!

Thanks gesf!
Post Reply