mysql_fetch_*
Posted: Thu Jul 14, 2005 12:40 pm
take a look at the following:
now what i would like to ask is how does PHP know that it needs to jump to the NEXT row after the {stuff} part of the while loop is executed? there isn't any indication, but it does select the next row. for example, mysql_result function is clear - you indicate the row you want to use elements of by using an int. don't get me wrong, i understand how the above while works, but for me it would appear that the given loop is infinite: from this ($row = mysql_fetch_assoc($result)) you get the first row of the $result and if the latter assignment expression is true (provided the table has records, it is), the {stuff} is executed. then we start over with the same again and again - assign the first row, check, do {stuff} - seems like infinite. where's the indication 'select the next row'? there isn't any and it doesn't need it, but it does select the next row. yeah, it's convenient to have it that way, but for me it seems like it's doing more than it is told to do. 
Code: Select all
$query = 'select head, body from news';
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
echo $row['head'] . '<br>';
echo $row['body'] . '<br><br>';
}