PHP MySQL Using the ORDER BY Clause

PHP MySQL Using the ORDER BY Clause
In PHP MySQL Using the ORDER BY Clause allows you to sort query results in ascending (ASC) or descending (DESC) order. You can use it with SELECT statements in PHP.
Using mysqli (Procedural)
ASC→ ascending (default),DESC→ descending
Using mysqli Object-Oriented
- Sorts users by name in descending order.
Using PDO
- PDO supports the same ORDER BY syntax as MySQL.
Using Multiple Columns
You can order by more than one column:
First sorts by age ascending
Then sorts by name descending if ages are equal
Key Points
ORDER BY sorts the query results.
Use ASC for ascending (default) and DESC for descending order.
Multiple columns can be used for secondary sorting.
Works with mysqli procedural, object-oriented, and PDO.
Combine with WHERE to filter results before sorting.
