How can the issue of only displaying the first value or last value when populating dropdown options using a while loop in PHP be resolved?

Issue: The problem occurs because the while loop fetches all the values from the database, but only the first or last value is displayed in the dropdown due to the pointer position after the loop finishes. To resolve this, we need to reset the pointer position to the beginning of the result set before populating the dropdown options.

// Reset the pointer position to the beginning of the result set
mysqli_data_seek($result, 0);

// Populate dropdown options using a while loop
echo '<select>';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<option value="' . $row['value'] . '">' . $row['label'] . '</option>';
}
echo '</select>';