Skip to content
PHP Logo

When using ORDER BY in PHP to sort data, what are the potential pitfalls to watch out for in terms of sorting order (ASCending vs DESCending)?

When using ORDER BY in PHP to sort data, one potential pitfall to watch out for is the sorting order specified (ASCending vs DESCending). If not specified correctly, the data may not be sorted as intended. To avoid this issue, always double-check the sorting order specified in the query to ensure the data is sorted correctly.

php
// Example of sorting data in descending order
$query = "SELECT * FROM table_name ORDER BY column_name DESC";
$result = mysqli_query($connection, $query);

// Example of sorting data in ascending order
$query = "SELECT * FROM table_name ORDER BY column_name ASC";
$result = mysqli_query($connection, $query);