How can PHP be used to query data from multiple databases and display only certain results based on a specific condition?

To query data from multiple databases and display only certain results based on a specific condition in PHP, you can establish connections to each database using mysqli or PDO, then execute separate queries to retrieve the data. Once you have the results, you can loop through them and apply the condition to filter out the desired results for display.

// Establish connections to multiple databases
$database1 = new mysqli('localhost', 'username1', 'password1', 'database1');
$database2 = new mysqli('localhost', 'username2', 'password2', 'database2');

// Execute queries on each database
$query1 = $database1->query("SELECT * FROM table1");
$query2 = $database2->query("SELECT * FROM table2");

// Fetch and display results based on a specific condition
while($row = $query1->fetch_assoc()) {
    if($row['condition'] == 'specific_value') {
        echo $row['column_name'] . "<br>";
    }
}

while($row = $query2->fetch_assoc()) {
    if($row['condition'] == 'specific_value') {
        echo $row['column_name'] . "<br>";
    }
}