PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } catch (Throwable $e) { http_response_code(500); echo json_encode(['error' => 'DB error']); exit; } // === GET ALL PLACES === $places = $pdo->query(" SELECT id, name, woj FROM salon_places ORDER BY woj ASC, name ASC ")->fetchAll(); $result = []; foreach ($places as $place) { // === GET SHOPS FOR PLACE === $stmt = $pdo->prepare(" SELECT address, open_hours, url_address, url_shop, lat, lng FROM shops WHERE place_id = ? ORDER BY address ASC "); $stmt->execute([$place['id']]); $shops = []; foreach ($stmt as $shop) { $shopItem = [ 'lat' => (string)$shop['lat'], 'lng' => (string)$shop['lng'], ]; if (!empty($shop['address'])) { $shopItem['address'] = $shop['address']; } if (!empty($shop['open_hours'])) { $shopItem['openHours'] = $shop['open_hours']; } if (!empty($shop['url_address'])) { $shopItem['urlAddress'] = $shop['url_address']; } if (!empty($shop['url_shop'])) { $shopItem['shopUrl'] = $shop['url_shop']; } $shops[] = $shopItem; } $result[] = [ 'type' => "city", //! do sprawdzenia czy city jest potrzebne 'name' => $place['name'], 'woj' => $place['woj'] === null ? false : $place['woj'], 'shops' => $shops ]; } echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); exit;