Home php PHP and MySQL. Sort ORDER BY

PHP and MySQL. Sort ORDER BY

Author

Date

Category

The main page contains buttons that process the same request, but with different search terms

(select id, name from table where yx = 1; select id, name from table where yx = 2 ...)

Query results are processed and displayed on a separate page.
Tell me how you can sort the resulting list?


Answer 1, authority 100%

Add an ORDER BY: construct to the end of the query

select id, name from table where yx = 1 ORDER BY id ASC;

ASC – sort in ascending order
DESC – sort descending

You can also combine fields and ways of sorting them:

select id, name from table where yx = 1 ORDER BY id ASC, name DESC;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions