PHP - 如何将两个不同的JSON输出合并为一个

My php server is generating two JSON output

1.] For MySql JSON printing I am using this code.

$sql = "select id ,Title , Meassage from lodhinews";
$result = $conn->query($sql);
$values = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    $values['data'][] = array(
        'id'=>$row['id'],
        'Title'=>$row['Title'],
        'Meassage'=>$row['Meassage']    
    );
}
header('Content-Type: application/json;charset=utf-8');
echo json_encode($values ,JSON_PRETTY_PRINT); 
} else {
$values = array(
    'error'=>'No results found'
);

}
$conn->close();
?>

2.] For file name printing I am using this code

chdir('./uploads');
foreach(glob('*.*') as $filename){
$data[] = $filename; 
}
echo json_encode($data);
?>

both the above code is working fine!

I wanted this both json output combined on one single page

查看全部
duanfuchi7236
duanfuchi7236
2016/01/26 10:22
  • json
  • php
  • echo
  • parsing
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复