Where should the code for creating an HTML table be placed in relation to the PHP script fetching data from MySQL?

The code for creating an HTML table should be placed after the PHP script that fetches data from MySQL. This ensures that the table is populated with the data retrieved from the database. By separating the PHP script for fetching data and the HTML code for displaying it, you can maintain a clean and organized structure in your code.

<?php
// PHP script to fetch data from MySQL
// Connect to the database and fetch data here

// HTML code for creating a table
echo "<table>";
echo "<tr><th>Column 1</th><th>Column 2</th></tr>";

// Loop through the fetched data and populate the table rows
while ($row = mysqli_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td>" . $row['column1'] . "</td>";
    echo "<td>" . $row['column2'] . "</td>";
    echo "</tr>";
}

echo "</table>";
?>