Jimmy Ruska's Blog
Php TutorialsCache Slow Pages for Performance
Youtube subscription Checker
Resizing images in PHP
Zip a File with PHP
Getting next auto_increment value from Mysql
Install PHP, MySQL, Apache the Bullet Proof Way
Benchmark your PHP with 3 lines of code
See all 7 posts
Php Tutorials RSS

Categoriesvideo tutorials (123)
funny pictures (30)
amazing pictures (11)
amazing videos (8)
php tutorials (7)
computer tricks (7)
hilarious videos (6)
personal updates (3)
youtube tips (3)
misc (3)
apache (2)
fake news (2)
articles (2)
cat videos (1)
My WebsitesBest of Internet
Streaming Anime Episodes
Free Video Tutorials
Best of Youtube
Electronics Discounts
MP3s From Google
Free Online Education
Funny Pictures Blog
Video Game Sheet Music
Free Movies Online
Online Degrees
College Online
Feb 13 | Getting next auto_increment value from Mysql Posted on Wednesday, February 13 2008 |
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());
$row=mysql_fetch_array($qry);
$newtid=$row[10];
$row=mysql_fetch_array($qry);
$newtid=$row[10];
Reset autoincrement
Here's how to reset the auto_increment too
ALTER TABLE tablename AUTO_INCREMENT = 1
Tags: get auto increment value, set autoincrement, reset id values my sql

Share:
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.