如何使用一个php脚本从sql中的两个不同表进行查询并将其解析为一个json对象?谢谢!
这是我的php
<?php
$sql = "select * from schedule;";
$sql1 = "select * from matches;";
$con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
$result = mysqli_query($con,$sql);
$result1 = mysqli_query($con,$sql1);
$response = array();
while($row=mysqli_fetch_array($result))
{
array_push($response, array("n_name"=>$row[1],"start"=>$row[4],"end"=>$row[5],"venue"=>$row[6]));
}
$data = array();
while($row=mysqli_fetch_array($result1))
{
array_push($data, array("teamone"=>$row[1]));
}
echo json_encode (array("schedule_response"=>$response, $data));
mysqli_close($con);
?>
这是输出
{"schedule_response":
[{
"n_name":null,
"start":"2016-11-09 00:00:00",
"end":"2016-11-16 00:00:00",
"venue":"aaaaaa"
}],
"0":[{"teamone":"aaa"}]}
我想要的是这样的东西
{"schedule_response":
[{
"n_name":null,
"start":"2016-11-09 00:00:00",
"end":"2016-11-16 00:00:00",
"venue":"aaaaaa",
"teamone":"aaa"
}]
}