I have two MySQL output which I need to encode in a single JSON output.
Output 1:
$sql = "select * from t1 ORDER BY id DESC LIMIT 25";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$output[] = array_map("nl2br", $row);
}
Output 2:
$sql2 = "select * from t2 ORDER BY id DESC LIMIT 25";
$result2 = $conn->query($sql2);
while($row2 = $result2->fetch_assoc()) {
$output2[] = array_map("nl2br", $row2);
}
This is what I am doing to get them in single JSON_encode:
echo json_encode($output.$output2);
still not getting both the outputs. I came to know of another solutions i.e. to merge both the queries but I am not able to do that as well. I referred this question also but no luck :(
json_encode(array($output, $output2));