How can the issue of multiple database entries being concatenated into a single string be resolved when populating a select element in PHP?

When populating a select element in PHP with data from a database, if multiple entries are being concatenated into a single string, the issue can be resolved by looping through the database results and creating individual option elements for each entry. This ensures that each database entry is displayed as a separate option in the select element.

<?php
// Assume $dbResult contains the database query result

echo '<select>';
foreach ($dbResult as $row) {
    echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
}
echo '</select>';
?>