How can PHP be used to display data from a MySQL table in a table format on a webpage?

To display data from a MySQL table in a table format on a webpage using PHP, you can connect to the database, query the table for the data you want to display, and then loop through the results to create an HTML table. You can use functions like mysqli_connect, mysqli_query, and mysqli_fetch_assoc to achieve this.

<?php
// Connect to MySQL
$connection = mysqli_connect("hostname", "username", "password", "database");

// Check connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Query the table
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Create HTML table
echo "<table border='1'>";
echo "<tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>";

while ($row = mysqli_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td>" . $row['column1'] . "</td>";
    echo "<td>" . $row['column2'] . "</td>";
    echo "<td>" . $row['column3'] . "</td>";
    echo "</tr>";
}

echo "</table>";

// Close connection
mysqli_close($connection);
?>