if($_GET["date"] == "new"){
$date_sort_text = "Oldest";
$date_sort_param = "old";
}else{
$date_sort_text = "Newest";
$date_sort_param = "new";
}
echo "<ol>
<li>Sort By ></li>
<li><a href=\"sort.php?" . http_build_query( array_merge($_GET, array("date" => $date_sort_param)) ) . "\">$date_sort_text</a>
<li><a href=\"sort.php?" . http_build_query( array_merge($_GET, array("views" =>"most"))) . "\">Most Views</a>
<li><a href=\"sort.php?" . http_build_query( array_merge($_GET, array("rating" =>"top"))) . "\">Top Rated</a>
</ol>" ;
or you could avoid code duplication by putting a function in place
if($_GET["date"] == "new"){
$date_sort_text = "Oldest";
$date_sort_param = "old";
}else{
$date_sort_text = "Newest";
$date_sort_param = "new";
}
echo "<ol>
<li>Sort By ></li>
<li><a href=\"" . getLink('date', $date_sort_param). "\">$date_sort_text</a>
<li><a href=\"" . getLink('views', 'most') . "\">Most Views</a>
<li><a href=\"" . getLink('rating', 'top') . "\">Top Rated</a>
</ol>" ;
function getLink($key, $value){
return 'sort.php?' . http_build_query( array_merge($_GET, array($key => $value)));
}