|
-
Feb 25th, 2004, 01:04 PM
#1
Thread Starter
Ex-Super Mod'rater
MySQL: Auto Incrementing [Resolved]
When using the auto increment ability on my primary key I want to also find out what the next value of it will be. Does anyone know how to do this?
Thanx
Last edited by Electroman; Feb 25th, 2004 at 08:58 PM.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 25th, 2004, 06:35 PM
#2
Member
You could use mysql_insert_id() to grab the last insert ID, then add one to it.
-
Feb 25th, 2004, 06:41 PM
#3
Thread Starter
Ex-Super Mod'rater
Not sure how that works, if I added the new record letting the auto increment sort out the id then ran mysql_insert_id() would it return the id I just created?
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 25th, 2004, 08:52 PM
#4
Stuck in the 80s
Originally posted by Electroman
Not sure how that works, if I added the new record letting the auto increment sort out the id then ran mysql_insert_id() would it return the id I just created?
Yes.
-
Feb 25th, 2004, 08:58 PM
#5
Thread Starter
Ex-Super Mod'rater
Thank you.
Have now completed that script, Unique Visitors Counter  . I actually worked round it by calculating what it should be, because the number is actually used in the same statement, but I think I'll redo it using this method. Then do an Update statement after it to include it in the record.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Feb 26th, 2004, 07:14 AM
#6
I think there's also LAST_INSERT_ID and NEXT_INSERT_ID functions that you can use in SQL statements.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 26th, 2004, 12:15 PM
#7
Stuck in the 80s
Originally posted by CornedBee
I think there's also LAST_INSERT_ID and NEXT_INSERT_ID functions that you can use in SQL statements.
Yes, there is. But I always found it easier to just use the PHP function. I guess there's really no difference. I'm sure the PHP function just calls a query for LAST_INSERT_ID.
A long time ago, Matt, phpman, and I had a big debate about how to do this properly. I don't think we ever resolved anything, but there might be something worthwhile in the thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|