looping through database results
| From: | Karl Nelson | Date: | Sun, 30 Sep 2001 21:45:44 +0000 |
| Subject: | looping through database results | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-69388@lists.php.net to get a copy of this message | ||
I'm working on a basic calendar app in PHP, but I've hit a snag.
The events are stored in a MySQL database, and the goal is to have the
events displayed on the correct day on the calendar. The calendar is
generated through a couple of while() statements that loop through the weeks
and days. I'm having trouble getting the events from the database match up
with the correct days.
I think the problem is that I can only loop through the database results
once.
The code looks something like this (lots of extraneous stuff trimmed):
while ($day_of_week <= 6)
{
while ($event_row = mysql_fetch_array($events))
{
$event_day = $event_row["event_day"];
if ($event_day == $day)
{
$event_name = $event_row["event_name"];
print "$event_name\n";
}
}
}
Since it seems to only loop through the while ($event_row =
mysql_fetch_array($events)) statement once (instead of the 30 times I want
it to loop through), I figure the issue is that after the one loop,
$event_row does indeed equal mysql_fetch_array($events). So I try to unset
the $event_row after the loop, but that didn't work. I even tried to make
$event_row into a variable variable name. Couldn't get that to work either.
I'm running PHP version 4.0.6, if that matters.
thanks,
Karl
(feel free to cc karlnelson@earthlink.net, as I'm on the digest)