Answer the question
In order to leave comments, you need to log in
How can you organize changes in the order of displaying rows from a table?
Hello.
There is a table with categories, you need to make it so that you can change their location (make the buttons lower to the bottom and raise to the top)
The question is, which field needs to be done in order to select records later.
For example, I have an idea to add a field "location" with type int to the table. with a default value of 0, and when pressed up, add 1 to this value, when pressed down, it is exactly the opposite.
And then to select through ORDER BY `location` DESC
But my variant has jambs.
How to do it rationally? It seems to be an elementary problem ... But I can’t solve it normally (:
Answer the question
In order to leave comments, you need to log in
> But my version has jambs.
And which ones do you think?
An alternative is to specify previous_id or next_id, then you will store a minimum of information about the order. In fact, it will be a linked list. To move any element, it will be enough to change 2-3 lines.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question