What are some best practices for efficiently displaying database records in PHP using loops and conditional statements?

When displaying database records in PHP, it is important to use loops and conditional statements efficiently to iterate through the records and display them appropriately. One common approach is to use a while loop to fetch each record from the database and then use conditional statements to format and display the data as needed.

<?php
// Assume $result is the result of a database query
while ($row = mysqli_fetch_assoc($result)) {
    // Displaying data from the database
    echo "Name: " . $row['name'] . "<br>";
    echo "Age: " . $row['age'] . "<br>";
    
    // Using conditional statements to display additional information
    if ($row['gender'] == 'male') {
        echo "Gender: Male<br>";
    } else {
        echo "Gender: Female<br>";
    }
    
    echo "<br>";
}
?>