What are some common pitfalls when trying to output data from a database in PHP, especially when dealing with multiple records?

One common pitfall when outputting data from a database in PHP, especially with multiple records, is not properly looping through the result set. To solve this, you need to use a loop, such as a while loop, to iterate over each record and output the data accordingly.

// Assuming $result is the result set from a database query

while($row = mysqli_fetch_assoc($result)) {
    echo "Name: " . $row['name'] . "<br>";
    echo "Age: " . $row['age'] . "<br>";
    // Add more fields as needed
}