<?php
include 'config.php';

$response = array();

$sql = "SELECT * FROM stories ORDER BY created_at DESC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $stories = array();
    while($row = $result->fetch_assoc()) {
        $stories[] = $row;
    }
    $response['success'] = true;
    $response['stories'] = $stories;
} else {
    $response['success'] = false;
    $response['message'] = "No stories found";
}

echo json_encode($response);
$conn->close();
?>