php - What is the best approach to sort MySQL table rows by user choice? -


suppose have mysql table (id , name) , drag-and-drop-enabled list view of table. user drags 90th row , places on 10th row. best approach keep new sorting?

  • i not mean keep sorting every use separately
  • the html/javascript not problem

i have seen programmers add weight column table, setting lower number upper in table. in example 1 100. the problem in case of above example (90 10) updating 81 rows required. 90 changes 10 , each 10 89 increments. efficient in mysql? there better solution?
way maybe saving new order string in table, but in case lose mysql sorting in retrieval phase!

i remember when learned trie tree structure in university indexing tool, said wow! when took advantage of every single bit of byte, 1.5 gb of pure text data stored in less 500kb!!! right still search find better answer!

even programming languages when updating indexes array had object added in occupied index adds 1 each index.

you're going have end updating index every single row.

the cleanest way (where people non trivial table of course):

update people set index = index + 1 index between $newindex , $oldindex; 

depending on database, between might include or exclude high , low bound numbers. make sure know how treats them!


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -