CREATE TABLE item ( link MEDIUMINT UNSIGNED PRIMARY KEY NOT NULL,
title TEXT NOT NULL,
rank INT UNSIGNED NOT NULL AUTO_INCREMENT,
notes TEXT
) ENGINE = INNODB;
I'm having trouble implementing this. rank is a user given ranking that can be changed at any time, and items can be added and removed at any time. The problem is I would like the ranks to be unique, and always ordered between 1 and n (n being the number of rows in the table). I.E.: If a user changes the rank of item 5 to 2. The previous rank 2 item should become rank 3, the previous rank 3 goes to rank 4, and the previous rank 4 becomes the new rank 5. Similarly, for delete and create, all larger or smaller ranked items should cascade down one or up one respective of the operation.
Is there some kind of pattern or technique for easily implementing this?
Thanks for any help,
Michael