<?php
// get_slider.php

header('Content-Type: application/json');
require 'db_connect.php';

$response = ['status' => 'error', 'message' => 'An unknown error occurred.'];

$sql = "SELECT id, image_url, title FROM sliders";
$result = $conn->query($sql);

if ($result) {
    $sliders = [];
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            $sliders[] = $row;
        }
    }
    // Return the array of sliders, which will be an empty array if there are no rows
    echo json_encode($sliders);
} else {
    $response['message'] = 'Database query failed.';
    echo json_encode($response);
}

$conn->close();
?>