How can the issue of multiple table outputs be resolved in this PHP script?
Issue: The PHP script is outputting multiple tables instead of consolidating the data into a single table. This can be resolved by ensuring that the table creation and data insertion are done outside of the loop. Solution: To resolve the issue of multiple table outputs, we need to move the table creation and data insertion outside of the loop. By doing this, we can consolidate all the data into a single table.
<?php
// Create a table before the loop starts
echo "<table border='1'>";
echo "<tr><th>Name</th><th>Age</th></tr>";
// Loop through the data and insert rows into the table
foreach ($data as $row) {
echo "<tr><td>" . $row['name'] . "</td><td>" . $row['age'] . "</td></tr>";
}
// Close the table after the loop ends
echo "</table>";
?>