{"result": [
{
"room_id": "1",
"floor_id": "1",
"flat_id": "1",
"room_name": "Room1",
"no_of_cots": "4",
"cot_info":[{"cot_id": "1",
"cot_name": "COT1",
"cot_status": "1"},
{"cot_id": "2",
"cot_name": "COT2",
"cot_status": "1"}],
"flat_name": "Sumangali PG",
"floor_name": "GroundFloor"
},
{
"room_id": "2",
"floor_id": "1",
"flat_id": "1",
"room_name": "Room2",
"no_of_cots": "2",
"cot_info":[{"cot_id": "1",
"cot_name": "COT1",
"cot_status": "1"},
{"cot_id": "2",
"cot_name": "COT2",
"cot_status": "1"}],
"flat_name": "Sumangali PG",
"floor_name": "GroundFloor"
} ]
}
答案 0 :(得分:0)
好的,您可以在查询示例中使用两个页面进行处理
应该是这样的,然后您可以将其添加到数组中,然后对数组进行解码并像例例中那样进行回显:
//page source
$query ='select room_id,floor_id,flat_id,room_name,no_of_cots,cot_info,cot_id,cot_name,cot_status,flat_name,floor_name
from table1 ,table2,table3,table4 where table1.id=table2.id and table2.id=table3.id and table4.id=table3.id';
$result = mysqli_query($conn,$query);
$array_list=array();
while($row = mysqli_fetch_array($result))
{
$array_list['room_id']=$row;
$array_list['floor_id']=$row;
$array_list['flat_id']=$row;
$array_list['room_name']=$row;
$array_list['cot_info']=$row;
$array_list['cot_name']=$row;
$array_list['cot_id']=$row;
$array_list['cot_status']=$row;
$array_list['flat_name']=$row;
$array_list['floor_name']=$row;
}
$json_data = array(
"result" => $array_list,
);
echo json_encode($json_data);
// page 2
$content='{"result": [ { "room_id": "1", "floor_id": "1", "flat_id": "1", "room_name": "Room1", "no_of_cots": "4", "cot_info":[{"cot_id": "1", "cot_name": "COT1", "cot_status": "1"}, {"cot_id": "2", "cot_name": "COT2", "cot_status": "1"}], "flat_name": "Sumangali PG", "floor_name": "GroundFloor" }, { "room_id": "2", "floor_id": "1", "flat_id": "1", "room_name": "Room2", "no_of_cots": "2", "cot_info":[{"cot_id": "1", "cot_name": "COT1", "cot_status": "1"}, {"cot_id": "2", "cot_name": "COT2", "cot_status": "1"}], "flat_name": "Sumangali PG", "floor_name": "GroundFloor" } ] }';
$json=json_decode($content);
foreach($json->result as $row)
{
print_r($row);
}