[ciapug] Iterating an empty result set

Carl Olsen carl-olsen at mchsi.com
Thu Feb 2 18:36:38 CST 2006


I've done this before.  You create two arrays and merge them.

Carl

-----Original Message-----
From: ciapug-bounces at cialug.org [mailto:ciapug-bounces at cialug.org] On Behalf
Of Chris Van Cleve
Sent: Thursday, February 02, 2006 9:18 AM
To: ciapug at cialug.org
Subject: [ciapug] Iterating an empty result set

I am displaying a 5 day outlook of upcoming events. Each day displays a 
box with the date at the top, and any events for that day below. That's 
all fine and dandy, but I've run into a problem ad for whatever reason 
I can't get my head wrapped around it today.

If the db query returns an empty result set (there are no events over 
the next five days), none of the boxes show. Here is the code I'm using 
(note: the DL is for CSS formatting. Yes it's a cheap trick. No I'm not 
after comments on it.):

$cal_sql = "SELECT * FROM ipm_events WHERE event_date BETWEEN CURDATE() 
AND CURDATE() + 5";

$events = $idb->Execute("$cal_sql");

$month = date(F);

$day_events = "<ul id='events'>\n";

while (!$events->EOF)
{
   for ($i=0; $i < 5; $i++)
   {
     $day = date(d) + $i;

     if ($events->fields['event_description'] == "")
     {
       $events = 'No Events';
     } else {
       $events = $events->fields['event_description'];
     }

   	$day_events .= "<dl class='events'>
       	 <dt><img src='/images/calendar/events/month_" . $month . ".png' 
title='" . $month . "'>
              <img src='/images/calendar/events/day_" . $day . ".png' 
title='" . $day . "'></dt>
       	 <dd>" . $events . "</dd>
       	</dl>";
   	$events->MoveNext();
   }
}

$day_events .= "</ul>\n";

The catch is obviously the use of:

  while (!$events->EOF)

With an empty result set, it is EOF immediately, so no event boxes 
display on the page. What should I be using to iterate that will allow 
all 5 days to display even if there are absolutely no events over those 
days?

Chris VC

_______________________________________________
ciapug mailing list
ciapug at cialug.org
http://cialug.org/mailman/listinfo/ciapug



More information about the ciapug mailing list