UNIX_TIMESTAMP() ORDER BY dateline DESC', [ 'type' => $type, 'lids' => $locations, ]); // Get one for each location. As we sort by dateline and check expiry in the query, we only // need one per location and then pick the first one that is set, as the locations are ordered // by closest to furthest $locations = array_flip($locations); foreach ($res as $row) { $lid = (int)$row['locationid']; if (is_array($locations[$lid])) continue; // Already have one $locations[$lid] = $row; } // Pick first one foreach ($locations as $row) { if (is_array($row)) break; } if (is_array($row)) { $title = htmlspecialchars($row['title']); $content = htmlspecialchars($row['content']); echo << $title $content {$row['dateline']} EOF; } else { // no news in DB, output a 'null' news xml echo '' . "\n"; echo "null"; }