Incremental number

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Incremental number

Postby SirChick » 31. July 2007 18:12

If i use an incremental number as unique and primary key for users.... so first record is 1 then next is 2 etc


Say i delete row 3 and 4 how can i get it so that the next 2 registrations that occur will take up ID 3 and ID 4, instead of going to the end of the database? would this require a script or is there a method of doing it in the database itself?


oops: please move to the english board! my bad!
SirChick
 
Posts: 68
Joined: 19. June 2007 15:03
Operating System: Windows 7 64 bit

Postby martinpre » 31. July 2007 20:37

what should the program do if you hav user 1,2,3 and 4 and you delete user 2 and then a new user come?
martinpre
 
Posts: 405
Joined: 22. May 2006 16:14
Location: Nähe Tulln / Österreich

Re: Incremental number

Postby jrav » 31. July 2007 23:03

SirChick wrote:Say i delete row 3 and 4 how can i get it so that the next 2 registrations that occur will take up ID 3 and ID 4, instead of going to the end of the database?

With the version of mySql I am using, it works like this by default....have you experienced behaviour different than this?
Last edited by jrav on 01. August 2007 17:43, edited 1 time in total.
jrav
 
Posts: 18
Joined: 26. July 2007 19:39

Postby SirChick » 01. August 2007 13:02

umm i think you misread.


I want it to full up the numbers that are not ther. An example:


1
2
3
4
5

say i remove row 3.

1
2
4
5

now the newest person signs up, by default it becomes number 6. But i want it to be number 3 cos number 3 is not there. Meaning it will fill up the ID numbers that have been removed before just going on to the last ID number like so:

1
2
4
5
3
SirChick
 
Posts: 68
Joined: 19. June 2007 15:03
Operating System: Windows 7 64 bit

Postby jrav » 01. August 2007 17:47

In that case, you want the ALTER TABLE command

http://dev.mysql.com/doc/refman/4.1/en/alter-table.html
jrav
 
Posts: 18
Joined: 26. July 2007 19:39

Postby SirChick » 01. August 2007 18:29

Ok, i dont have the confidence with that yet thats for sure lol
SirChick
 
Posts: 68
Joined: 19. June 2007 15:03
Operating System: Windows 7 64 bit

Postby jrav » 01. August 2007 20:02

You can do it!

In the file where you delete users, add....

ALTER TABLE tableName AUTO_INCREMENT = 1;

after the deletion. Change tableName to the name of your table and it should work as requested.
jrav
 
Posts: 18
Joined: 26. July 2007 19:39

Postby SirChick » 02. August 2007 00:39

ok so i add this php to it at the end of the code?
SirChick
 
Posts: 68
Joined: 19. June 2007 15:03
Operating System: Windows 7 64 bit

Postby SirChick » 02. August 2007 00:41

what exactly will that code do just so im sure ya understood what i needed...
SirChick
 
Posts: 68
Joined: 19. June 2007 15:03
Operating System: Windows 7 64 bit


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 98 guests