How can SELECT queries with different WHERE conditions be outsourced and included on various pages in PHP?

To outsource SELECT queries with different WHERE conditions and include them on various pages in PHP, you can create a separate PHP file containing the query logic and then include this file in the pages where you need to execute the query. This way, you can reuse the query code across multiple pages without duplicating it.

// query.php
<?php
function getResults($condition) {
    $sql = "SELECT * FROM table_name WHERE condition = '$condition'";
    // Execute the query and return results
}
?>

// page1.php
<?php
include 'query.php';
$results = getResults('condition1');
// Use the results as needed
?>

// page2.php
<?php
include 'query.php';
$results = getResults('condition2');
// Use the results as needed
?>