How can the ORDER BY clause be properly integrated into a SQL query in PHP?

When using the ORDER BY clause in a SQL query in PHP, you need to include it at the end of the query before executing it. The ORDER BY clause allows you to sort the results based on a specific column in ascending or descending order. Make sure to specify the column you want to sort by and the desired order direction (ASC for ascending, DESC for descending).

$query = "SELECT * FROM table_name ORDER BY column_name ASC";
$result = mysqli_query($connection, $query);

// Fetch and display the sorted results
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['column_name'] . "<br>";
}