diff --git a/public_html/directory.php b/public_html/directory.php index 68168a971..906d9f469 100644 --- a/public_html/directory.php +++ b/public_html/directory.php @@ -383,31 +383,23 @@ function DIR_displayYear($template, $dir_topic, $year) $mResult = DB_query($monthSql); $numMonths = DB_numRows($mResult); + // The above query returns records with duplicate months. So, let's sort them out. if ($numMonths > 0) { - $items = array(); - $lastMonth = 1; - for ($j = 0; $j < $numMonths; $j++) { - $M = DB_fetchArray($mResult); - - for (; $lastMonth < $M['month']; $lastMonth++) { - $items[] = DIR_monthLink($dir_topic, $year, $lastMonth, 0); - } - $lastMonth = $M['month'] + 1; + $numArticles = array_fill(1, 12, 0); - $items[] = DIR_monthLink($dir_topic, $year, $M['month'], $M['cnt']); + while (($M = DB_fetchArray($mResult, false)) !== false) { + $month = (int) $M['month']; + $cnt = (int) $M['cnt']; + $numArticles[$month] += $cnt; } - if ($year == $currentYear) { - $fillMonth = $currentMonth; - } else { - $fillMonth = 12; - } + $items = array(); + $lastMonth = ($year == $currentYear) ? $currentMonth : 12; - if ($lastMonth <= $fillMonth) { - for (; $lastMonth <= $fillMonth; $lastMonth++) { - $items[] = DIR_monthLink($dir_topic, $year, $lastMonth, 0); - } + for ($month = 1; $month <= $lastMonth; $month++) { + $items[] = DIR_monthLink($dir_topic, $year, $month, $numArticles[$month]); } + $retval .= COM_makeList($items); } else { if (TEMPLATE_EXISTS) {