Re: looping through database results

From: Date: Sun, 30 Sep 2001 21:59:14 +0000
Subject: Re: looping through database results
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-69390@lists.php.net to get a copy of this message
On Sunday, September 30, 2001, at 02:45 PM, Karl Nelson wrote:
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.
Try using: while ($event_row = mysql_fetch_row($events)) instead. mysql_fetch_row will grab one row of the result array at a time, until there are no more rows. This sounds like what you want. What you were doing was grabbing the entire result array and storing them in one variable. Hope this helps, Andrew Elliston

« previous php.general (#69390) next »