[ciapug] Iterating an empty result set
Carl Olsen
carl-olsen at mchsi.com
Thu Feb 2 18:40:00 CST 2006
That's the easy way. In my case I wanted to display the hours in a day
(which I had in one table) and the events (which could be on any or none of
the hours). I created two arrays and merged them, which is similar to using
the "for loop" to create the 5 items for the first array.
Carl
-----Original Message-----
From: ciapug-bounces at cialug.org [mailto:ciapug-bounces at cialug.org] On Behalf
Of Tony Bibbs
Sent: Thursday, February 02, 2006 9:41 AM
To: ciapug at cialug.org
Subject: Re: [ciapug] Iterating an empty result set
Something like this?
for ($i=0; $i < 5; $i++) {
if ($events->EOF) {
// print blank boxes
} else {
// print data in boxes
}
}
Chris Van Cleve wrote:
> 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
_______________________________________________
ciapug mailing list
ciapug at cialug.org
http://cialug.org/mailman/listinfo/ciapug
More information about the ciapug
mailing list