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 Link to comment https://forums.phpfreaks.com/topic/31093-re-sorting-table-order-after-deleting-some-entries/ 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") Link to comment https://forums.phpfreaks.com/topic/31093-re-sorting-table-order-after-deleting-some-entries/#findComment-143761 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. Link to comment https://forums.phpfreaks.com/topic/31093-re-sorting-table-order-after-deleting-some-entries/#findComment-144130 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. Link to comment https://forums.phpfreaks.com/topic/31093-re-sorting-table-order-after-deleting-some-entries/#findComment-144575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.