What are best practices for including database query results in external PHP files for display?

When including database query results in external PHP files for display, it is best practice to separate your database logic from your display logic. One way to achieve this is to store the query results in a variable in your main PHP file and then include the external PHP file where you want to display the results. This helps keep your code organized and makes it easier to maintain and update in the future.

// main.php
$db_results = // perform database query here

include 'display_results.php';

// display_results.php
foreach ($db_results as $result) {
    echo $result['column_name'] . '<br>';
}