What are some best practices for sorting data in PHP when using mysql_query?

When sorting data in PHP using mysql_query, it is best practice to include the ORDER BY clause in your SQL query to specify the sorting order. This helps ensure that the data is returned in the desired order.

// Connect to database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query to select data from table and sort by a specific column
$query = "SELECT * FROM table_name ORDER BY column_name ASC";
$result = mysqli_query($connection, $query);

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

// Close the connection
mysqli_close($connection);