Instead of

  /* keep going with days.... */ 
  for($list_day = 1; $list_day &lt;= $days_in_month; $list_day++):
      $calendar.= '&lt;td class="calendar-day"&gt;';
      /* add in the day number */ 
      $calendar.= '&lt;div class="day-number"&gt;'.$list_day.'&lt;/div&gt;';

      /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !!  
          IF MATCHES FOUND, PRINT THEM !! **/ 

      $calendar.= str_repeat('&lt;p&gt;&amp;nbsp;&lt;/p&gt;',2);
      $calendar.= '&lt;/td&gt;';
      if($running_day == 6):
          $calendar.= '&lt;/tr&gt;';
          if(($day_counter+1) != $days_in_month):
              $calendar.= '&lt;tr class="calendar-row"&gt;';
          endif;
          $running_day = -1;
          $days_in_this_week = 0;
      endif;
      $days_in_this_week++; $running_day++; $day_counter++;
  endfor;


do

   /** QUERY THE DATABASE FOR AN ENTRY FOR THE PERIOD !!  
          IF MATCHES FOUND, STORE THEM !! **/ 
  $entries = getEntriesFromDB($month,$year);

  /* keep going with days.... */ 
  for($list_day = 1; $list_day &lt;= $days_in_month; $list_day++):
      $calendar.= '&lt;td class="calendar-day"&gt;';
      /* add in the day number */ 
      $calendar.= '&lt;div class="day-number"&gt;'.$list_day.'&lt;/div&gt;';
      if ($entries[$list_day]):
          /** ADD THE ENTRIES FOR THE DAY!! **/
      endif;
      $calendar.= str_repeat('&lt;p&gt;&amp;nbsp;&lt;/p&gt;',2);
      $calendar.= '&lt;/td&gt;';
      if($running_day == 6):
          $calendar.= '&lt;/tr&gt;';
          if(($day_counter+1) != $days_in_month):
              $calendar.= '&lt;tr class="calendar-row"&gt;';
          endif;
          $running_day = -1;
          $days_in_this_week = 0;
      endif;
      $days_in_this_week++; $running_day++; $day_counter++;
  endfor;


More seriously, in the first case you'd have a query like

SELECT date,event from entries where date = $date


and now you'd have

SELECT date,event from entries where date between $date_minus_one_month and $date


Then store the results in an associative array, indexed by days.

PHP and MySQL calendar issue
Suppose the time-series $X$ is hidden state Gaussian random walk and we observe $Y = X + e$,  where $e$ is gaussian white noise independent of $X$.

The Kalman estimator of $X$ in this case has a steady state closed form solution and corresponds to an exponential moving average smoother with constant smoothing parameter. The optimal smoothing parameter looks like $\lambda = \frac{p}{1-p}$  where $p$ is a quadratic formula of signal to noise ratio between $e$ and $\Delta{x}$. See formula for closed form (by searching 'kalman solu‌​tion random walk noise').

If we have instead multiple independent observations $Y_1, Y_2,...$, i.e. independent $e_1, e_2,...$ is there a closed form solution for the optimal estimator of $X$?    What would it look like? 

If the $e_1, e_2$ were independent and identically  distributed (same standard deviation), I can imagine the best estimator for $X$ is to simply average the estimators obtained treating the problem as univariate for each $Y$.

If the $e_1,e_2,...$ have different variance, then some $Y$ series should have low weightings in the overall estimator as their signal to noise ratio is poorer. Perhaps the closed form solution is linear with coefficients proportional to each $Y$ signal to noise ratio.

Is there a known closed form solution? Google seems not to be too helpful on this problem.
