I need to combine two MySQL result variables since I have two different hosts and union all function cannot use in the query. Here is my attempt. First I retrieved the results as below:
$stmt_ch = $conn_1->prepare("SELECT ts,number from blocklist where number like ?");
$stmt_ch->bind_param('s', $num_remove);
$stmt_ch->execute();
$result_ch = $stmt_ch->get_result();
$stmt_ch2 = $conn_2->prepare("SELECT ts,number from blocklist where number like ?");
$stmt_ch2->bind_param('s', $num_remove);
$stmt_ch2->execute();
$result_ch2 = $stmt_ch2->get_result();
Var_dump( $result_ch)
gives me an array, so I decided to merge these two arrays as below. Maybe I am wrong.
$result_ch_com = array_merge($result_ch, $result_ch2);
Then tried to use as below:
if($result_ch_com->num_rows > 0){
-------
}
Seems this is wrong too. Maybe I am completely wrong, I have no idea. My intention is to show all the results in one table. Can someone help me on this?
I have already checked this thread, Combine two arrays, to get an idea to combine arrays but it didn't work for me
Update:
if(count($result_ch_com) > 0){
$output .= '
<table class="table table-bordered">
<tr>
<th width="25%" style="text-align:center">Blocked Time</th>
<th width="20%" style="text-align:center">Blocked Number</th>
</tr>
';
foreach($result_ch_com as $row) {
$output .= '
<tr>
<td style="text-align:center">'.$row['ts'].'</td>
<td style="text-align:center">'.$row['number'].'</td>
</tr>
';
}
$output .= '</table>';
echo $output;
}
}