<?php
include '../db.php';

if ($conn->connect_error) {
    die(json_encode(["error" => "Database connection failed"]));
}

// Base URL for uploaded images
$baseUrl = "http://localhost/petite-backend/about/uploads/";

$sql = "SELECT section, paragraph1, paragraph2, image1, image2 FROM about_us";
$result = $conn->query($sql);

$data = [];
while ($row = $result->fetch_assoc()) {
    $data[$row['section']] = [
        "paragraph1" => $row['paragraph1'],
        "paragraph2" => $row['paragraph2'],
        "image1" => $row['image1'] ? $baseUrl . basename($row['image1']) : null,
        "image2" => $row['image2'] ? $baseUrl . basename($row['image2']) : null
    ];
}

echo json_encode($data);

$conn->close();
