How can one effectively display the results of a MySQL query in PHP?

To effectively display the results of a MySQL query in PHP, you can use a combination of PHP and HTML to loop through the query results and output them in a readable format. You can fetch the results using functions like mysqli_fetch_assoc() or mysqli_fetch_array() and then display them using a loop like foreach or while loop.

<?php
// Assuming $conn is the MySQL database connection object and $query is the SQL query
$result = mysqli_query($conn, $query);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo "<p>Name: " . $row['name'] . "</p>";
        echo "<p>Email: " . $row['email'] . "</p>";
        // Add more fields as needed
    }
} else {
    echo "No results found.";
}
?>