RE: [PHP] Query result to an array
| From: | Martin Towell | Date: | Thu, 12 Sep 2002 06:55:33 +0000 |
| Subject: | RE: [PHP] Query result to an array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-116097@lists.php.net to get a copy of this message | ||
> > $result = mysql_query(...);
> while( $t = mysql_fetch_row($result) ){
> $array[] = $t;
> }
>
> No. I need a 2 dimensions arrays, each line of this array, is the result
> of one row of the query and each cell of this row is a field from the
> select.
>
> Example, the query return 2 row and 3 fields for each row :
> "Christian", "Ista", "Belgium"
> "zak", "PhpNet", "Dontknowfrom"
>
> resulf of SELECT NAME, LASTNAME, COUNTRY FROM MyTable;
>
> I'd like to put that in an array and later because I use a session array.
>
> I'd like via a for loop access these data by
> echo(MyArray[1][1]); result is "PhpNet"
> echo(MyArray[0][2]); result is "Belgium"
> echo(MyArray[1][0]); result is "zak"
>
> Is it clearer now ?
>
> Thanks,
>
> Christian
>
That's exactly what this will do. mysql_fetch_row() returns an array.
Appending that to another array and you get back an array of arrays (which
is the same as a 2D array)
Try it and see...
Martin