if($_GET["sortby"] == "topic" and $_GET["section"] != "") {
$result = mysql_query("select *, DATE_FORMAT(date, '%W, %M %D, %Y') as formatted_date from dailyg_archives where series <> 999 and (topic = '$_GET[section]') and (`sent`=1) order by date desc");
} elseif ($_GET["sortby"] == "date" and $_GET["section"] != "") {
list($month, $year) = explode("_", $_GET["section"]);
$result = mysql_query("select *, DATE_FORMAT(date, '%W, %M %D, %Y') as formatted_date from dailyg_archives where series <> 999 and(MONTHNAME(date) = '$month' and YEAR(date) = '$year') and (`sent`=1) order by date desc");
} else {
$result = mysql_query("select *, DATE_FORMAT(date, '%W, %M %D, %Y') as formatted_date from dailyg_archives where (series = '$_GET[section]') and (`sent`=1) order by date desc");
}
while($message = mysql_fetch_assoc($result)) {
?>