[ciapug] Iterating an empty result set
Chris Van Cleve
vanish at dreamscapevisionery.com
Thu Feb 2 09:18:19 CST 2006
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
More information about the ciapug
mailing list