<?php

require 'conexion.php';

$data = array();

$query = "SELECT image_url FROM splash_screen WHERE actived = 1 ORDER BY last_activated DESC LIMIT 2;";

$stmt = $connect->prepare($query);
$stmt->execute();
$result = $stmt->get_result();

if ($result && $result->num_rows > 0) {
    if ($result->num_rows == 1) {
        while ($row = $result->fetch_assoc()) {
            // Adding only image_url to the $data array
            $data[] = $row['image_url'];
            $data[] = $row['image_url'];
        }
    }
    while ($row = $result->fetch_assoc()) {
        // Adding only image_url to the $data array
        $data[] = $row['image_url'];
    }
    // Returning the image_url array as JSON
    echo json_encode($data);
} else {
    echo json_encode(array('message' => 'No data found'));
}
