我正在创建一个帖子存档,我想在以年/月格式创建文章时创建存档链接。
数据库中创建的日期以YYYY-MM-DD
格式存储,到目前为止已经写了。
$archive =
mysql_query("SELECT DISTINCT DateCreated FROM blog ORDER by DateCreated")
or die("Could not execute query");
while($row = mysql_fetch_array($archive) ){
$Date = explode("-", $row["DateCreated"]);
$Year = $Date[0];
$Month = $Date[1];
// Months of the year.
$MonthName = array(
"01" => "JAN",
"02" => "FEB",
"03" => "MAR",
"04" => "APR",
"05" => "MAY",
"06" => "JUN",
"07" => "JUL",
"08" => "AUG",
"09" => "SEP",
"10" => "OCT",
"11" => "NOV",
"12" => "DEC");
$archiveData .=
"<a href='archive.php?".$Year."-".$Month.
"'>".$MonthName[$Month]."-".$Year."</a><br />";
}
如果我将这些日期存储在我的数据库中
2012-04-07,
2012-05-02,
2012-05-13,
2012-02-22,
然后上面的代码生成链接为
FEB-2012,
APR-2012,
MAY-2012,
MAY-2012,
它显示了已经添加的月份,我需要做的是限制它只显示一次。
我想我需要更改查询但不确定如何获得我需要任何帮助的结果将不胜感激。