views:

168

answers:

2

What is the easiest way to turn a mysql result variable into a multidimensional array in php?

Thanks

+8  A: 

Run mysql_fetch_assoc in a loop.

while ($row = mysql_fetch_assoc($result)) {
    $table[] = $row;
}

print_r($table);
Byron Whitlock
+1  A: 

if you happen to be using the mysqli extension and php 5.3, you could use http://us2.php.net/manual/en/mysqli-result.fetch-all.php

Jason
Or <code>$statement->fetchAll()</code> for PDO.
Bart van Heukelom