get auto increment to work at such a number... help :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

get auto increment to work at such a number... help :(

Post by lizlazloz »

hi. i have a MySQL table of users, so when they sign up they are assigned an id number, so the first user gets 1, the second 2, and so on.

well, i created an account through phpmyadmin with id 100000, just to test a few things out. now when a new user makes an account they are given the next numbers up from 100000, so 100001, 100002 etc...

i have deleted the account with id 100000, and all with ids above that, but new accounts are still going up from 100000. I have turned auto-increment off, but then all the new accounts made get id 0. i then turned auto_increment back on, but i still ahve the same problem. what can i do to get new account's IDs starting from the highest numebr currently in the table, as they should?

please help, and thanks for reading.
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

There is no rule that says that it'll always start at the lowest available number.

To reset the count, you have to remake the table.

Alternatively, you could manually do things the way you want to by making it NOT auto-increment and instead inserting the number yourself. You'd find the number by finding the current max and adding 1.
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Post by lizlazloz »

ok, thanks.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Actually in phpMyAdmin you can change the id auto_increment number. Just do this:

1. Select the table you want
2. Press the "Operations" tab in the right frame
3. Scroll down to the bottom and you will see a box with a number with auto_increment written next to it.
4. Change it to whatever you want and press Go.

**Note: You might want to delete all the entries in the database, I'm not sure what affect this might have if you reach the id numbers already set. It shouldn't be a big deal as long as you have the ID field set to Primary, which will make all ID numbers unique.
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post by genetix »

I agree with DuFF thats what I always do. ITS SO MUCH HANDIER! :wink:
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

or else, you can just create a new id-field, with the same optins, and it'll start from 1 or 0 again :wink:
drakkon
Forum Newbie
Posts: 3
Joined: Wed Dec 31, 2003 11:51 am

Post by drakkon »

Just tried to do this but my version of php myadmin didn't have that option under 'operations'. So I found the code to do it manually.

If you go into SQL tab and run
ALTER TABLE `tbl_name` AUTO_INCREMENT = #

Where # is the number you want auto_increment to start.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

afaik mysql doesn't allow to set a new value for AUTO_INCREMENT that is smaller then the old. You may skip some values but not rewind.
The purpose of auto_increment is to create a unique identifier for each record set and it would be less unique if you could decrease the value.
Post Reply