Jimmy's Blog Jimmy Ruska's Blog
Getting next auto_increment value from Mysql Posted on Wednesday, February 13 2008
Learn to Play Songs by Ear: Ear Training

It can be useful in some situations to grab a post's id value before it's even posted. For example, I use it to rename my pictures to the corresponding post and embed them on the page. There's no "select auto_increment from table" command in mysql. If you say just say "select id+1 from table order by id desc", it will give you an incorrect value if you have deleted your latest post. You could post, then edit, then repost, but that's not very efficient at all. The best way I've found is use the show table status query below.

$qry=mysql_query("show table status where name='newblog'") or die (mysql_error());

Reset autoincrement

Here's how to reset the auto_increment too


Tags: get auto increment value, set autoincrement, reset id values my sql

stumble digg delicious

Blog by Jimmy Ruska
Add me: Youtube, Twitter, Facebook, MySpace


More OMFG-Good Links

See all Posts in the Funny Pictures category.
Download mp3s faster than limewire using google.
I've made 100+ free video tutorials.
See the best of the internet today on one page.