mysql userID problem

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
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

mysql userID problem

Post by pleigh »

if i have a users table like below:
userID name
1 apple
2 banana
3 cherry
4 durian
5 earrth
6 farm
7 gooseberry
8 hogplum
9 indian mango
10 jackfuirt
when i tried to delete one row, let's say, userID 1, name apple, then i tried to refresh the database, the 2nd name, banana bacame the first in the list with the userID still 2, like below:
userID name
2 banana
3 cherry
4 durian
5 earrth
6 farm
7 gooseberry
8 hogplum
9 indian mango
10 jackfuirt
instead of banana being the userID # 2, i want it to be # 1 since the apple is deleted. is there any way i can do it?also, when i tried to reboot the computer, this is still the case.i already set the userID to auto_increment.

thanks in advance.

pleigh[/list]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have to manually update all records that appear after that id number. Then update the table's auto_increment value to the new maximum.

However, auto_incremented fields are not supposed to be used for counting. That's what COUNT() and mysql_num_rows() are for..
Post Reply