D
D
Dokuro2015-10-28 20:59:11
PHP
Dokuro, 2015-10-28 20:59:11

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

1 answer(s)
S
Stanislav Makarov, 2015-10-28
Chan @iDokuro

> 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 question

Ask a Question

731 491 924 answers to any question