|
-
Tiger Shark
PHP/MySQL questions
I have started working with PHP and so far things have gone very well although I am having some trouble with a MySQL database. I have a field in my database that acts as a record number and is set to auto increment. The auto increment part of things works but how do I adjust the value of the field if I need to jump around the database for a update or delete. Basically how can I manually change the value of the record number field?
------------------
[SGC Ultimate pass... Don't read anything I post unless you want a headache ]
[Member of the Sharky High-Resolution Club]
-
Ursus Arctos Moderatis
Hmmm, I'm not sure if I entirely follow you here.
You have an Auto-Number field, and that should be your Primary Key, or in MySQL terms, defined as Primary-Indexed-Unique.
You should never change the value of your Primary key, and why would you want to in the first place? If you change that records unique identifier, than you run the risk of data corruption.
Did I just not follow your question right? If so, please try to re-word your question.
-
Reef Shark
Values that you may need to change in the future shouldn't be autoincrement - you'll have to add another field to the table...
moog
------------------
No Norm, those are your safety glasses... I'll wear my own thanks.
No Norm, those are your safety glasses... I'll wear my own thanks.
-
Tiger Shark
Ok how's this. If delete all the entries in the db and then proceed to add a new entry the record number field will pick up where it last left off. So if the last record was number 9 and then I delete everything in the db and add a new record the record number will be set to 10 when I want it set to 0. Does that help any?
------------------
[SGC Ultimate pass... Don't read anything I post unless you want a headache ]
[Member of the Sharky High-Resolution Club]
-
If its an autoincrement primary key, then you cannot get it to set back to zero without deleting the table and recreating it. One of the rules of primary keys is that they are to be unique and only be used once, even if deleted. (However, there may be a switch in MySQL somewhere I don't know about). You will have this problem in Access also.
To make this work you will need to do the incrementing yourself. Create a numerical field, then whenever you add a record, find the maximum value of that field and make the new record be that value + 1.
------------------
--------------------
"Log, its better than bad, its good!"
--------------------
When you were born you cried and the world smiled. Live your life so that when you die you smile and the world cries.
-
Reef Shark
That's one of the 'features' of autonumber fields - you've always got a unique field in the database no matter whether you subsequently delete records.
So - if you want this value to be zeroed or whatever, you'll have to either turn off the auto-increment or create a new field in the db. In both cases you'll have to set the value yourself using PHP when you write the record.
Hope this helps.
moog
------------------
No Norm, those are your safety glasses... I'll wear my own thanks.
No Norm, those are your safety glasses... I'll wear my own thanks.
-
Tiger Shark
Originally posted by moog:
That's one of the 'features' of autonumber fields - you've always got a unique field in the database no matter whether you subsequently delete records.
So - if you want this value to be zeroed or whatever, you'll have to either turn off the auto-increment or create a new field in the db. In both cases you'll have to set the value yourself using PHP when you write the record.
Hope this helps.
moog
Thanks for the help!
------------------
[SGC Ultimate pass... Don't read anything I post unless you want a headache ]
[Member of the Sharky High-Resolution Club]
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
|
|