What are some common methods in PHP to display SQL query results on the same page as an HTML form?

When displaying SQL query results on the same page as an HTML form in PHP, you can use methods such as storing the query results in a variable and echoing them within the HTML code, or using a loop to iterate through the results and display them dynamically. Another common approach is to use a combination of PHP and HTML to create a table or list format for the query results.

<?php
// Perform SQL query
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Display query results in HTML form
echo "<table>";
while ($row = mysqli_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td>" . $row['column1'] . "</td>";
    echo "<td>" . $row['column2'] . "</td>";
    // Add more columns as needed
    echo "</tr>";
}
echo "</table>";
?>