views:

129

answers:

3
while (list($task_id, $parent_id, $task) = mysqli_fetch_array($r, MYSQLI_NUM))
+5  A: 

It fetches a row (from a MySQL query) into the array with the columns task_id, parent_id, and task until there are no more rows to fetch. The list() function converts these columns into the $task_id, $parent_id, and $task variables for use in the while loop.

In other words: It iterates through a rowset.

Eric
+! I agree, but maybe you should also explain what list() does in the context of a while loop, as it's a pain to read, even for experienced PHP'ers IMHO.
karim79
It's certainly not very clear, that much is sure... someone is too lazy to type $row to make it clear
Matthew Scharley
+1  A: 

http://us3.php.net/manual/en/mysqli-result.fetch-array.php

Just in case you didn't know what mysqli_fetch_array was.

Troggy
+12  A: 

it's a loop through a result set, with a compressed conversion from a mysql result row to individual variables

the long way would be:

while($row=mysqli_fetch_array($result)){
    $task_id   = $row[0];
    $parent_id = $row[1];
    $task      = $row[2];

    // Do something with the row data
}

the relevant pages in the PHP doc are:

Convert an array to a set of variables: http://php.net/list

Fetching a row of a mysqli result object: http://php.net/manual/en/mysqli-result.fetch-array.php

GApple
What is MYSQLI_NUM for?
Delirium tremens
The second parameter to mysql_fetch_array() is a constant to specify the format of the return array: MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH. Essentially, should the array be indexed by field names, integers, or both (two values exist in the array for the same data). The documentation page has excellent explanations of the MySQLi extension.
GApple