36326-vm/api/locations.php
2025-11-26 15:44:00 +00:00

23 lines
711 B
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../db/config.php';
try {
$pdo = db();
// Fetch listings that are either assigned or collected, and have coordinates
$sql = "SELECT name, quantity, latitude, longitude, status, pickup_by
FROM food_listings
WHERE (status = 'assigned' OR status = 'collected')
AND latitude IS NOT NULL AND longitude IS NOT NULL";
$stmt = $pdo->query($sql);
$locations = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($locations);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['error' => 'Database error']);
// error_log($e->getMessage());
}