<?php

$cat_id = intval($map['cat']);
$us_id = intval($map['us_id']);
$us_timestamp = intval($map['us_timestamp']);

$previous_id = $GLOBALS['SITE_DB']->query_select_value_if_there('news', 'id', array('news_category' => $cat_id), ' AND date_and_time<' . strval($us_timestamp));

if ($previous_id === null) {
    return;
}

$previous_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $previous_id), '_SEARCH');

echo '<a href="' . escape_html($previous_url->evaluate()) . '">Previous</a>';
