How can the mysql_query() and mysql_fetch_array() functions be effectively combined to retrieve and display data from a MySQL database in PHP?

To retrieve and display data from a MySQL database in PHP, you can use the mysql_query() function to execute a SQL query and then use the mysql_fetch_array() function to fetch the results as an associative array. By looping through the fetched array, you can display the data in your desired format.

// Connect to MySQL database
$connection = mysql_connect("localhost", "username", "password");
mysql_select_db("database_name", $connection);

// Execute query
$result = mysql_query("SELECT * FROM table_name");

// Fetch and display data
while ($row = mysql_fetch_array($result)) {
    echo "ID: " . $row['id'] . "<br>";
    echo "Name: " . $row['name'] . "<br>";
    echo "Email: " . $row['email'] . "<br>";
    // Add more fields as needed
}