By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

How to get the next auto-increment value?

P: 18
Hi there!

How should I write a query to get the next auto-increment value of a table?

Many thanks in advance for any help.

Best regards,
Gerry
Feb 26 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
I'm not sure it's possible..
I'd sure like to see some answers though!

Edit:
After the intruige overtook me, i had a swift google, and this is what i found.. looks credible:
[php]
<?
$tablename = "tablename";
$next_increment = 0;
$qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'";
$qShowStatusResult = mysql_query($qShowStatus) or die ( "Query failed: " . mysql_error() . "<br/>" . $qShowStatus );

$row = mysql_fetch_assoc($qShowStatusResult);
$next_increment = $row['Auto_increment'];

echo "next increment number: [$next_increment]";
?>
[/php]
I havent tested it though.. going to have a blast now!
Feb 26 '08 #2

harshmaul
Expert 100+
P: 490
OMG, thats genious. It worked for me, and i been lookin for that code half heartedly for a while now. cheers markusn00b
Feb 26 '08 #3

Markus
Expert 5K+
P: 6,050
OMG, thats genious. It worked for me, and i been lookin for that code half heartedly for a while now. cheers markusn00b
Well i'm glad i could be of assistance!
:P
Feb 26 '08 #4

P: 18
Hi Markus!
Thank you for your reply which I used and test : it works!
Best regards,
Gerry
Feb 27 '08 #5

Markus
Expert 5K+
P: 6,050
Hi Markus!
Thank you for your reply which I used and test : it works!
Best regards,
Gerry
Good luck!
regards
Feb 27 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.