manual ordering of rows
Posted: Mon May 23, 2005 9:20 am
hi
i have table of links. there is a field in a table called "order".
i use it to manually specify the order in which these links are displayed
e.g. $qr="SELECT * FROM links ORDER BY order ASC";
links | order
---------------
link1 -> 4
link2 -> 1
link3 -> 3
link4 -> 5
link5 -> 2
...
the "problem" is that if i want to add new link say in position 3 then i should either
- increase value of "order" by 1 for all links where value of "order">=3
or
- decrease value of "order" by 1 for all links where value of "order"<=3
i saw someone's code that deals with this situation by selecting appropriate rows and then loop over them each time updating value of "order" field...
somehow, i don't like this method.it is good for small number of rows.
Maybe someone knows other ways more efficient ways to do manual ordering?
i have table of links. there is a field in a table called "order".
i use it to manually specify the order in which these links are displayed
e.g. $qr="SELECT * FROM links ORDER BY order ASC";
links | order
---------------
link1 -> 4
link2 -> 1
link3 -> 3
link4 -> 5
link5 -> 2
...
the "problem" is that if i want to add new link say in position 3 then i should either
- increase value of "order" by 1 for all links where value of "order">=3
or
- decrease value of "order" by 1 for all links where value of "order"<=3
i saw someone's code that deals with this situation by selecting appropriate rows and then loop over them each time updating value of "order" field...
somehow, i don't like this method.it is good for small number of rows.
Maybe someone knows other ways more efficient ways to do manual ordering?