What are the differences between using a for loop and a while loop when iterating through database results in PHP?

When iterating through database results in PHP, using a for loop is beneficial when you know the exact number of rows to iterate over, while a while loop is more suitable when the number of rows is unknown. For loops are typically faster and more efficient, but while loops provide more flexibility in handling different scenarios.

// Using a for loop to iterate through database results
$result = $mysqli->query("SELECT * FROM table");
for ($i = 0; $i < $result->num_rows; $i++) {
    $row = $result->fetch_assoc();
    // Process each row here
}
``` 

```php
// Using a while loop to iterate through database results
$result = $mysqli->query("SELECT * FROM table");
while ($row = $result->fetch_assoc()) {
    // Process each row here
}