Jump to content

[SOLVED] Auto Increment


SJames

Recommended Posts

So, you know how when you have an auto-incremented mysql list? And you know how when you delete an entry, the entry's auto-increment value just gets dropped and skipped?

 

What I need to know is if there is a way to sort of re-number the list, preferably using a Query, such as an ALTER command or something.

 

I have a page that lists the entries like so:

 

1 Title A

2 Title B

3 Title C

4 Title D

 

When an entry is deleted, it looks like this:

 

1 Title A

3 Title C

4 Title D

 

I need to be able to change the previous into this:

 

1 Title A

2 Title C

3 Title D

 

 

I also need to know if there is a way to re-number the list, but  alphabetically by title. (This would be a seperate command.)

 

For Example:

 

1 Title B

2 Title C

3 Title A

 

Would become:

 

1 Title A

2 Title B

3 Title C

Link to comment
https://forums.phpfreaks.com/topic/67387-solved-auto-increment/
Share on other sites

If you change the numbers, then any other table which references those rows will be meaningless. There is a good reason to keep the numbers the same. Why do you want to change them?

 

You can sort them in PHP to make new arrays, but don't try to edit the tables in MySQL.

Link to comment
https://forums.phpfreaks.com/topic/67387-solved-auto-increment/#findComment-338224
Share on other sites

The whole point of a relational database is relationships. And relationships are established from record ids in different tables.  The best way to destroy the usefulness of a database is to mess around with record numbers.  Imagine that auto-incrmented ids are owned by MySQL not you, and you'll be a lot less likely to suffer a database disaster.  If what you really need is a counter, make one in the loop you use to retrieve and display data.

Link to comment
https://forums.phpfreaks.com/topic/67387-solved-auto-increment/#findComment-338231
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.