Re: while loop
| From: | Jack Dempsey | Date: | Tue, 10 Apr 2001 06:12:06 +0000 |
| Subject: | Re: while loop | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-47957@lists.php.net to get a copy of this message | ||
Zeus wrote:
>
> Isn't the '=' operator suppose to be used for assigning and not for
> evaluation.
>
yup.
> I thought '==' should be used in this context?
nope.
Thing is, you ARE assigning. Here's a breakdown of the controlling part
of the loop in english:
--->while ($row = mysql_fetch_array($query)) {
this can be thought of as this:
1. fetch an array from $query, which is a mysql result.
2. assign this value to $row
3. we do this AS LONG AS WE ARE ABLE TO FETCH THE ARRAY.
that's the while part
mysql_fetch_array keeps track of where it is in the array.
after each while loop it moves a 'step ahead' in the result
when it gets to the end, it can't fetch anymore information from your
result.
then it returns false.
thus, it can't assign a value to $row.
thus that statement is false.
therefore the while loop exits
> > > do stuffs;
> > > }
> > >
> > > someone correct me if I'm wrong?
> > >
> > > Zeus
> >
> > Consider yourself corrected :-) mysql_fetch-array returns an array
> > corresponding to the fetched row, or _false if there are no more rows_
> >
> > So as soon as there are no more rows, $row = mysql_fetch_array($query)
> > evaluates to false and the while exits.
> >
> > --
> > David Robley | WEBMASTER & Mail List Admin
> > RESEARCH CENTRE FOR INJURY STUDIES |
> > http://www.nisu.flinders.edu.au/
> > AusEinet |
> > http://auseinet.flinders.edu.au/
> > Flinders University, ADELAIDE, SOUTH AUSTRALIA
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net