the code I\'m looking at does this...
while ($info=mysql_fetch_array($data_jurisdiction))
{
//some stuff
}
I\'m wondering what does this wh
great answer from hakre. what is said is that
while ($info=mysql_fetch_array($data_jurisdiction))
will execute in the same way as this
while (mysql_fetch_array($data_jurisdiction)==true)
or even this
$info = mysql_fetch_array($data_jurisdiction);
if($info==true)
so keep in mind that if mysql_fetch_array($data_jurisdiction) returns anything that can be evaluated to false, the assignment won't work. some of those values are (and I know I will forget a few:
as long as $info gets assigned a value other than false, this code will execute?
Yes.
For each record $info
will be populated with the current row, until it reaches the end of the result set when it will be set to false (which should stop the while loop).
it does loop and stops if $info
is false
mysql_fetch_array();
clears row by row so there is new result alltimes
A while loop will execute the nested statement(s) repeatedly, as long as the while expression evaluates to true
.
The expression in your example $info = mysql_fetch_object($data_jurisdiction)
checks whether the $info
, the assigned value from mysql_fetch_object()
is equal to true, after type juggling.
It is important to understand two things here:
mysql_fetch_object()
returns the next row of the result set until the end of the data set is reached, where it returns false. See the method documentation here.null
evaluate to true after type juggling.From the manual:
The value of an assignment expression is the value assigned. That is, the value of "$a = 3" is 3.
Also from the manual about mysql_fetch_array:
Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows.
Therefore, once there are no more rows, the assignment will turn into:
$info = false
Which will get evaluated as false in the while condition, causing the loop to terminate.