我想从该页面抛出多个json,以便获取一个json文件,以显示使用Java编程的移动应用程序的输出。以下是我的代码,该代码显示表“ news”中的正确json,但是,我想抛出数据库中可用的其他对象的json。那可能吗?
$dblink = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
mysqli_query($dblink, 'SET NAMES utf8');
//Check connection was successful
if ($dblink->connect_errno) {
printf("Failed to connect to database");
exit();
}
$result = $dblink->query("SELECT * FROM news ORDER BY id DESC");
$dbdata = array();
while ( $row = $result->fetch_assoc()) {
$dbdata[]=$row;
}
echo json_encode($dbdata);
?>
答案 0 :(得分:2)
如何组合它们取决于您,它可能很简单:
合并:
array(a,b,c,d,a,b,c)
不同的键:
$dbdata = array_merge($dbdata1, $dbdata2);
echo json_encode(dbdata);
MySQL Join:
$dbdata = array(
'table_1' => $dbdata1,
'table_2' => $dbdata2
);
echo json_encode($dbdata);