What are the best practices for combining multiple query results and displaying them side by side in PHP?

When combining multiple query results in PHP and displaying them side by side, one approach is to fetch the results from each query and store them in separate arrays. Then, iterate over the arrays to display the data in a tabular format or any desired layout. This allows for a clear and organized presentation of the combined results.

// Assume $query1 and $query2 are the results of two separate SQL queries

// Fetch and store results from first query
$results1 = [];
while ($row = mysqli_fetch_assoc($query1)) {
    $results1[] = $row;
}

// Fetch and store results from second query
$results2 = [];
while ($row = mysqli_fetch_assoc($query2)) {
    $results2[] = $row;
}

// Display combined results side by side
echo "<table>";
echo "<tr><th>Query 1 Results</th><th>Query 2 Results</th></tr>";
for ($i = 0; $i < max(count($results1), count($results2)); $i++) {
    echo "<tr>";
    echo "<td>" . ($results1[$i]['column_name'] ?? '') . "</td>";
    echo "<td>" . ($results2[$i]['column_name'] ?? '') . "</td>";
    echo "</tr>";
}
echo "</table>";