Need help to return 2 query into a single table
Posted: Wed Jul 11, 2012 10:26 pm
Hello,
Need help to write php code which can return result of 2 query into a single table in different column
Here is my code
From code above, I tried to query from 2 different database and the result are return in separate table.
Instead of above, I want my result to look like this
How can I combine the result into single table in different column.
Thanks in advanced.
Need help to write php code which can return result of 2 query into a single table in different column
Here is my code
Code: Select all
<?php
...
$conn1 = db2_connect($database1, $user, $password);
$conn2 = db2_connect($database2, $user, $password);
if ($conn1) {
if ($conn2) {
$sql1 = $_POST["keyword1"];
$stmt1 = db2_exec($conn1, $sql1, array('cursor' => DB2_SCROLLABLE));
$columns1 = db2_num_fields($stmt1);
$col1 = ($columns1-1);
$name1 = db2_field_name($stmt1, $col1);
print("<table border = '1'>\n");
while ($row1 = db2_fetch_array($stmt1)) {
print "\t<tr><td>$row1[$col1]</td></tr>\n";
}
print("</table>\n");
db2_close($conn1);
}
$sql2 = $_POST["keyword2"];
$stmt2 = db2_exec($conn2, $sql2, array('cursor' => DB2_SCROLLABLE));
$columns2 = db2_num_fields($stmt2);
$col2 = ($columns2-1);
$name2 = db2_field_name($stmt2, $col2);
print("<table border = '1'>\n");
while ($row2 = db2_fetch_array($stmt2)) {
print "\t<tr><td>$row2[$col2]</td></tr>\n";
}
print("</table>\n");
db2_close($conn2)
;}
else {
echo "Fail to connect to both databases";
}
?>
Code: Select all
Query 1 result
1
2
3
Query 2 result
a
b
c
Code: Select all
Query 1 Result Query 2 Result
1 a
2 b
3 cHow can I combine the result into single table in different column.
Thanks in advanced.