rreynier Posted July 31, 2009 Share Posted July 31, 2009 Hey guys, I have created a little CMS project. There are several cases where I have content that needs to be able to be moved to the top or down.. etc. Right now, I just asdded a field called "order" and all my sql queries are doing "ORDER BY `order` ASC" The way to change order is just to have the user change the number manually when editting the item.. So if you have 2 items.. one with the value 50 will be at bottom and one with value of 1, will be at the top. I would like the user instead of having to put in a number in an input field, just be able to hit "move up" or "move down". My question is, how would I go about this. Im having a brainfree on how to do this logically. Thanks ahead of time! Quote Link to comment Share on other sites More sharing options...
phpknight Posted August 1, 2009 Share Posted August 1, 2009 If they click move up, then find the one above it the one below it. Then divide by two, and use the middle value. So, if one is 10 and the other is 20, make it 15. You can then infinitely have the order by using a float or double for the field instead of an int. Quote Link to comment Share on other sites More sharing options...
rreynier Posted August 3, 2009 Author Share Posted August 3, 2009 So, if the user clicks "move item up in order" find the next 2 entries that are higher in the list. Add them together and divide by two? So lets say the order value item is 16 and the next two are 17 and 18, I would get 17.5. Could this possibly get out of hand decimal point wise? Quote Link to comment Share on other sites More sharing options...
rreynier Posted August 3, 2009 Author Share Posted August 3, 2009 does anyone have any other methods, or is this the basic idea used in these types of systems? Quote Link to comment Share on other sites More sharing options...
phpknight Posted August 3, 2009 Share Posted August 3, 2009 It doesn't matter what the decimal points look like because all you care about is the ordering. So, I wouldn't worry about it. BUT, if you want, you could reset them every week or something to be multiples of 10. Quote Link to comment Share on other sites More sharing options...
rreynier Posted August 4, 2009 Author Share Posted August 4, 2009 ok cool. i will use your concept, thanks alot phpknight 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.