shaneg55 Posted September 13, 2010 Share Posted September 13, 2010 How to re order records after a delete or move? I have table of navigational items. lets say under "about us" i have 5 sub links and i order them by a field called theorder. How can a re order them properly if one is deleted? orders are 1,2,3,4,5 and if i delete the record that is 3 then the order is 1,2,4,5 but i want it to now become 1,2,3,4. How do i do this properly? Thanks Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/ Share on other sites More sharing options...
fenway Posted September 13, 2010 Share Posted September 13, 2010 You don't want this at all. If you want to number your records, do so in PHP -- leave the DB records alone. Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110588 Share on other sites More sharing options...
shaneg55 Posted September 13, 2010 Author Share Posted September 13, 2010 yeah. how was this comment helpful at all? Sorry to the almighty for not knowing all the rules or even finding the answer already posted (where?). If i dont want to order the results with mysql by a field which contains the order show me how to do it in php then! Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110597 Share on other sites More sharing options...
fenway Posted September 13, 2010 Share Posted September 13, 2010 My comment was extremely helpful -- I kept you from violating your database's referential integrity. Just a simple counter should do it -- if you need help with that, I'll move this to the php forum. Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110601 Share on other sites More sharing options...
shaneg55 Posted September 13, 2010 Author Share Posted September 13, 2010 yes i could do $i ++ during the loop of the records but i want to keep the sort order which may change in tact. like if im listing 5 links under a parent link and i have defined them in the order that i want using a field but i remove say the record that is sort order #3 then i need to change so sort order for the links becomes 1,2,3,4 not 1,2,3,5 . How will a counter or even php know what order i want these links in? what if i add a link or change the order of them down the road. Dont i have to do it via mysql with an ORDER BY satement not with php as php will not know what order i want them in? Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110609 Share on other sites More sharing options...
fenway Posted September 13, 2010 Share Posted September 13, 2010 Then you need a sortorder column. Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110622 Share on other sites More sharing options...
shaneg55 Posted September 13, 2010 Author Share Posted September 13, 2010 ok, and how do i re order the values after one is deleted? sortorder=1, 2, 3, 4, 5 etc. I remove the record with sortorder 3 now i need to re order the values so its sortorder = 1,2,3,4 etc not 1,2,4,5? Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110625 Share on other sites More sharing options...
Maq Posted September 13, 2010 Share Posted September 13, 2010 shaneg55, please don't create duplicate posts in different boards. fenway offered to move your thread and you went ahead and created one anyway. Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110664 Share on other sites More sharing options...
shaneg55 Posted September 13, 2010 Author Share Posted September 13, 2010 I apologize for posting in different boards (didn't know if this question would be best answered in mysql or php so i posted in both). I posted in both prior to Fenway's offer to move so its not like i didnt take Fenway up on the offer and went out of my way to do it anyway. I am still looking for an answer to this scenario if anyone is interested in posting. Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110667 Share on other sites More sharing options...
mikosiko Posted September 13, 2010 Share Posted September 13, 2010 ... I am still looking for an answer to this scenario if anyone is interested in posting. you got an answer in the other post.... the182guy gave you a good start.... just continue reading/posting there Link to comment https://forums.phpfreaks.com/topic/213289-new-order-after-delete/#findComment-1110679 Share on other sites More sharing options...
Recommended Posts