array help
| From: | Fletcher Mattox | Date: | Thu, 14 Jul 2005 22:33:36 +0000 |
| Subject: | array help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-218720@lists.php.net to get a copy of this message | ||
How does one represent a MySQL table as a two dimensional array
using the column names as one of the indices? My naive attempt
went something like this:
while ($row = mysqli_fetch_assoc($result))
$table[] = $row;
but that generated this error;
Fatal error: [] operator not supported for strings
Ok. So then I try to explicitly assign each row, like this:
while ($row = mysqli_fetch_assoc($result))
$table[$i++] = $row;
While that generates no error, $table contains nothing useful when
I'm done. So then I try to assign each row and column, like this:
while ($row = mysqli_fetch_assoc($result)) {
foreach ( $row as $col => $val)
$table[$i][$col] = $val;
$i++;
}
And that got me this error:
Fatal error: Cannot use string offset as an array
So clearly my understanding of PHP arrays is lacking.
Please help.
Thanks
Fletcher