Problem with Auto-Increment and Deleting

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
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Problem with Auto-Increment and Deleting

Post by bedcor »

When i delete a record from my MySQL database it works fine, but then when i reload the form to Insert another record, it sticks the record into the database but at the position where i deleted the record.

Can someone show me a way of keeping the autoincrement at the last record in the database even after i delete a record?

Thanx
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post by EricS »

Change your table type to MyISAM, your table is probably an ISAM.
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

How do i do that?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

ALTER TABLE `table_name` TYPE = MYISAM

Just replace table_name with the table you want to change
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

Thanks for the help, but can you tell me the difference between the two?
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Get the highest record number from the database.
Something like:

Code: Select all

select MAX(record_number) from database_table...
save it as a variable and increment it,

Code: Select all

$max_record=$rowї'(max)'] + 1;

Then submit it as a new record to the database with the rest of the data you need to store.

Direwolf
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post by EricS »

If you want the exact details lookup "MyISAM" and "ISAM". The short answer is that ISAM is the old table structure and MyISAM is the replacement. More features and more flexibility (like in the case where it solves your problems here!).
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Johnm wrote:Get the highest record number from the database.
Something like:

Code: Select all

select MAX(record_number) from database_table...
save it as a variable and increment it,

Code: Select all

$max_record=$rowї'(max)'] + 1;

Then submit it as a new record to the database with the rest of the data you need to store.

Direwolf
What if 2(or more) people do this at exactly the same time?
Post Reply