MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old October 10th, 2003, 11:10 PM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 116 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 49 sec
Reputation Power: 5
managing auto increment field in mysql

Hi guys,

I have created a table with a field call 'no' which i set to auto increment. The purpose of this field is to let me know how many clients i actually have in my database. Everytime i add a new cliet, i would put 0 in the no field so it will automatically put the last value for me..

but now i have a prob.. when the time i delete some of the row, the db seems to got prob... first prob is when i add a new row, it seems to replace the row i just deleted row but with different no.

For instance, i delete the row with no=1 and i wanna insert a new row that suppose to be the 23rd row... when i put the value for no field 0, it does inserted into db with the value 23 in no field. But the prob is the info that inserted does not seem to be correct. A part of the info in my newly inserted row seem to be the info of the row which i delete. It might sound strange but it really happened... may i know why this occured ?? is it i am not suppose to put 0 in the no field when insert new row ??? if that is the case, what i should put the value of no in the php code when i wanna insert a new row ??

another question i wish to ask is, is there anyway i can make it update the no field by itself if something is deleted ?? for instance i deleted the first row with no field value is 1, then the second row will replace the first one and the value of no field from the second row will automatically change to 1.. same goes to the other rows... is this possible ???

like in my case, if i delete a large number of files randomly, the auto increment number in my no field will start to get very messy. i just wish the auto increment works as what i expect..

please advise ...

Thanks.

Reply With Quote
  #2  
Old October 11th, 2003, 09:23 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
are you just trying to count how many users?

Reply With Quote
  #3  
Old October 11th, 2003, 09:51 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
You should never try to upate an auto_increment field. It does nothing but auto_increment. And you should set it to NULL rather than 0 when you insert a new row. If you want to get a count of your users, you should do "SELECT COUNT(*) FROM table" rather than messing with auto_increment values. Auto_increment fields are used to generate unique keys and really aren't meant to be used for generating counts, being edited, etc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > managing auto increment field in mysql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway