<?php

$us_id = intval($map['us_id']);

$secondary_cat = $GLOBALS['SITE_DB']->query_select_value_if_there('news_category_entries', 'news_entry_category', array('news_entry' => $us_id));
$next_id = $GLOBALS['SITE_DB']->query_select_value_if_there('news_category_entries', 'news_entry', array('news_entry_category' => $secondary_cat), ' AND news_entry>' . strval($us_id));

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

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

echo '<a href="' . escape_html($next_url->evaluate()) . '">Next Episode</a>';
