What are the best practices for optimizing price sorting in a database for a price comparison website?

When optimizing price sorting in a database for a price comparison website, it is important to ensure that the prices are stored in a consistent format (such as decimal) and indexed properly for efficient sorting. Additionally, using a proper SQL query with an ORDER BY clause can help sort the prices accurately and quickly.

// Example SQL query to retrieve prices from a database table and sort them in ascending order
$query = "SELECT price FROM products ORDER BY price ASC";
$result = mysqli_query($connection, $query);

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