D
D
Denis2020-04-18 12:22:50
PHP
Denis, 2020-04-18 12:22:50

Set up sorting on the site?

In general, I'm doing sorting on the site, I'm testing, and I don't understand one thing. Sorting for three fields - name mail and status. The name and mail of the norms work, i.e. when sorting name sort ASC, Vasya's first position, when clicking on name sort DESC, Vasya becomes the last one. All right. And the status field has the values ​​1 and 0, and when sorting status sort ASC - Olya is the last one, but when status sort DESC she should be the first, but this is not so. I don't understand why.. or is it supposed to be like this? How then to sort a field with such values?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Sarvarov, 2020-04-18
@megakor

In your case, you need to do multiple sorting if the sorting is by the status field.
I would choose two fields - status and ID.
Sort by status in ascending order would look like this:
ORDER BY status ASC, id ASC
Descending would look like this:
ORDER BY status DESC, id DESC

A
Andrey, 2020-04-18
@AndryG

When sorting by multiple fields, it is important to change not only the sort direction, but also the order of the fields. Perhaps it is with the order of the fields in sorting that you have a misunderstanding.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question