tags:

views:

225

answers:

3

when

$query = 'SELECT * FROM users';

and there are multiple columns/rows, does mysql_fetch_assoc($result) return a two-dimensional array?

Can I draw each row by simply saying: array_pop(mysql_fetch_assoc($r))

thanks!

+3  A: 

No, it returns a single row.

Calling it again will return the next row, until there are no more rows.

You can build a multi-dimensional array like this:

$rows = array();
while ($row = mysql_fetch_assoc($data))
    $rows[] = $row;
Greg
+6  A: 

*mysql_fetch_assoc* returns an associative array (an array with the selected column names as keys), one row at a time until there are no more rows in the result of the query. Call it in a loop to work with a row at a time:

while ($row = mysql_fetch_assoc($result)) {
    echo $row["username"];
    echo $row["email"];
}

(Assuming username and email are columns in the users table).

Siddhartha Reddy
+2  A: 

array_pop will unset the first value of the array and return it, so in your case your first table field would be unset.

John David Koise