How can data retrieved from a MySQL database be displayed in a visually appealing format on a website using PHP?

To display data retrieved from a MySQL database in a visually appealing format on a website using PHP, you can use HTML and CSS to style the output. You can create a dynamic HTML table to display the data in rows and columns, and use CSS to customize the appearance of the table, such as changing fonts, colors, and borders.

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

// Retrieve data from database
$query = "SELECT * FROM table";
$result = mysqli_query($conn, $query);

// Display data in a HTML table
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th></tr>";
while($row = mysqli_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td>".$row['id']."</td>";
    echo "<td>".$row['name']."</td>";
    echo "<td>".$row['email']."</td>";
    echo "</tr>";
}
echo "</table>";

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