$jk_photo[$k]['id'], 'url' => $jk_photo[$k]['url_server'], 'width' => NULL, 'height' => NULL, ]; } array_pop($result_photo); //get_item $jk_item = db_query_exec($db_connect, "SELECT * FROM lot_base WHERE jk_id = '$jk_id'"); for ($k=0; $k<=count($jk_item); $k++) { $lot_id = $jk_item[$k]['id']; //get_photo_lot $result_lot_photo = NULL; $lot_photo = db_query_exec($db_connect, "SELECT * FROM lot_base_photo WHERE lot_id = '$lot_id'"); for ($j=0; $j<=count($lot_photo); $j++) { $result_lot_photo[] = [ 'id' => $lot_photo[$j]['id'], 'url' => $lot_photo[$j]['url_server'], 'width' => NULL, 'height' => NULL, ]; } array_pop($result_lot_photo); $result_item[] = [ 'type' => 'Продажа', 'id' => $jk_item[$k]['id'], 'title' => $jk_item[$k]['lot_name'], 'address' => $jk_item[$k]['lot_adress'], 'lat' => NULL, 'lon' => NULL, 'fullPricexls' => $jk_item[$k]['lot_price'], 'squarePrice' => $jk_item[$k]['lot_price_m2'], 'currency' => '₽', 'rooms' => $jk_item[$k]['lot_bedroom'], 'residense' => $jk_info[$i]['jk_name'], 'residenceID' => $jk_id, 'street' => NULL, 'square' =>$jk_item[$k]['lot_square'] , 'bedroom' => $jk_item[$k]['lot_bedroom'], 'status' => 'Новостройка', 'floor' => explode (':', $jk_item[$k]['lot_floor'] )[0], 'floors' => explode (':', $jk_item[$k]['lot_floor'] )[1], 'wc' => NULL, 'otc' => $jk_item[$k]['lot_otc'], 'discriptions' => $jk_item[$k]['lot_description'], 'assigned' => [ 'name' => 'Фамилия Имя Отчество', 'position' => 'Должность', 'avatar' => NULL, ], 'commision' => NULL, 'actualDate' => $jk_item[$k]['lot_date_update'], 'mainPhoto' => $result_lot_photo, ]; } array_pop($result_item); $result[] = [ 'id' => $jk_info[$i]['id'], 'title' => $jk_info[$i]['jk_name'], 'address' => $jk_info[$i]['jk_adress'], 'lat' => NULL, 'lon' => NULL, 'mainPhoto' => $result_photo, 'items' => $result_item, ]; //echo $jk_info[$i]['jk_name']; //$lot_info = db_query_exec($db_connect, "SELECT * FROM lot_base WHERE jk_id = '$jk_id'"); } echo json_encode ($result); //print_r($result); //print_r(json_encode($result)); function db_connect ($db_host, $db_user, $db_password,$db_name) { $db_connect = mysqli_connect ($db_host, $db_user, $db_password, $db_name); mysqli_set_charset($db_connect, 'utf8'); if ($db_connect <> false) { return $db_connect; } else { return "Error connection to Database: ".mysqli_connect_error($db_connect); } } function db_query_exec ($db_connect, $db_query) { $db_query_exec = mysqli_query($db_connect, $db_query); if ($db_query_exec <> false) { while($db_query_exec_result_row = mysqli_fetch_assoc($db_query_exec)) { $db_query_exec_result_array[] = $db_query_exec_result_row; } return $db_query_exec_result_array; } else { return "Error query: ". mysqli_error($db_query_exec); } } ?>