首页 文章

想得到如下结果 . 如何为此编写查询

提问于
浏览 418
-3
{"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"
        } ]
}

1 回答

  • 0

    好的,您可以使用两个页面来查询查询示例
    应该像那样然后你可以添加到一个数组然后解码数组并使回声像在示例bellew中:

    //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);
    
    
    
    }
    

相关问题