What is the potential issue with using the same result set in multiple while loops in PHP?

When using the same result set in multiple while loops in PHP, the issue arises when the first loop iterates through all the rows, leaving the result set pointer at the end. Subsequent loops will not have any rows to iterate over. To solve this, you can store the rows in an array and loop through the array instead of the result set directly.

// Store rows in an array
$rows = [];
while($row = mysqli_fetch_assoc($result)) {
    $rows[] = $row;
}

// Loop through the array
foreach($rows as $row) {
    // Do something with each row
}

// Loop through the array again
foreach($rows as $row) {
    // Do something else with each row
}