...

View Full Version : Getting latest ID



kaisellgren
06-06-2007, 11:58 AM
Hi,

I have a database with id int unsigned not null auto_increment so the id increments automatically by 1 each time i insert something.

My questions is. I have 10 iteams in my db, when I delete the latest one, I have 9 items but the latest id is still 10. So how do I get this latest id?

Now I have used

SELECT id FROM table ORDER BY id DESC;

And then my $latest_id = $result +1;

But if I have deleted the latest row, then my biggest id would be 9 although my latest id is 10.

Help?

printf
06-06-2007, 01:22 PM
auto increment column types have nothing to do with how many rows are in the table, they are used solely as a unique identifier, where no single row can contain that same value, which makes it unique. But more importantly it's used to reference other tables that have a relationship with that unique number/key!

usmanrazzaq
06-07-2007, 12:35 PM
use
$latest_id=mysql_insert_id();
to get latest id that have been inserted but use it just after the insert query

kaisellgren
06-07-2007, 12:36 PM
Thanks I have resolved this issue.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum