Table listing of months
| From: | Ashley M. Kirchner | Date: | Sat, 09 Aug 2003 21:21:35 +0000 |
| Subject: | Table listing of months | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-158998@lists.php.net to get a copy of this message | ||
I have the following snippet of code:
<?php
// contents of $monthlyarchivereverse is generated by a different
// piece within a content managent system. The data, or format
// can not be changed.
$monthlyarchivereverse = array("/08/index.html August 2003",
"/07/index.html July 2003",
"/06/index.html June 2003",
"/05/index.html May 2003"
);
$monthlyarchive = array_reverse($monthlyarchivereverse);
function lightdark($rest) {
if ($rest%2) {
$color = "#eee";} else {
$color = "#fff";} return $color; } foreach ($monthlyarchive as $string) { list($link, $month, $year) = split(" ",$string); $shortmonth = substr($month,0,3); $a[$year][] = "<a href=\"$link\">$shortmonth</a>"; } reset($a); $array_first_key = key($a); while (count($a[$array_first_key]) < 12) { array_unshift($a[$array_first_key], " "); } foreach ($a as $year=>$list_of_strings) { echo "<table class=\"mcalendar\">\n"; echo " <tr><th colspan=\"4\" class=\"mcalendar\">$year</th></tr>\n <tr>\n"; foreach ($list_of_strings as $key=>$date_string) {
if($key%4 || $key==0) {
} else {
echo " </tr>\n <tr>\n";
}
echo " <td class=\"mcalendar\" style=\"background-color : ".lightdark($key).";\">".rtrim($date_string)."</td>\n";
}
echo " </tr>\n</table>\n";
}
?>
Which when run, will generate a table that looks like this, with each month hyperlinked to its respective link from the array:
+-----------------------+
| | | | |+-----------------------+
| | | | |+-----------------------+ | May | Jun | Jul | Aug | +-----------------------+ I now want to change this, to something like this: +-----------------------+ | Jan | Feb | Mar | Apr | +-----------------------+ | May | Jun | Jul | Aug | +-----------------------+ | Sep | Oct | Nov | Dec | +-----------------------+ ...where only those months that have an associated hyperlink will be linked, and the others will just be displayed without a link. How can I achieve this?