What is the correct syntax for displaying data retrieved from a MySQL database using fetch_array in PHP?

When retrieving data from a MySQL database using fetch_array in PHP, the correct syntax involves looping through the result set and accessing the data using the column names or indexes. To display the data, you need to echo or print out the values within the loop. Make sure to check if the result set is not empty before attempting to display the data.

// Assuming $result is the result set obtained from a MySQL query
if ($result->num_rows > 0) {
    while ($row = $result->fetch_array()) {
        echo $row['column_name']; // Display data using column names
        echo $row[0]; // Display data using indexes
    }
} else {
    echo "No results found.";
}