Chappers Posted December 18, 2006 Share Posted December 18, 2006 Hi all,I've got a MySQL database set up in which I have a field set as primary key and named ID, and auto_increment. As I display the elements sorted by ID order, I have the number of each entry in the table in numerical order going down the page, just as I want. But, if I delete any of the entries in the table, the numbers set for each ID remain static, so I might end up with:ID: 1 Name: blahID: 3 Name: blofID: 4 Name: blagwhere ID: 2 is missing because it's been deleted. Is there a way I can make the table re-sort itself so after deleting the above entry ID:2, the remaining table would be:ID: 1 Name: blahID: 2 Name: blofID: 3 Name: blagThanks,James Quote Link to comment Share on other sites More sharing options...
artacus Posted December 18, 2006 Share Posted December 18, 2006 Yes, but don't use your autoinc primary key like this. Use another field (I usually have a col named "sort_order") Quote Link to comment Share on other sites More sharing options...
Chappers Posted December 19, 2006 Author Share Posted December 19, 2006 Could you explain how please? I'm still learning and not finding it terribly easy. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 19, 2006 Share Posted December 19, 2006 Add a column and store a numeric value for the desired sort order in that column -- don't try and exploit the PK. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.