Re: Converting a MySQL result into a complex array
| From: | Curt Zirzow | Date: | Tue, 22 Jul 2003 00:19:02 +0000 |
| Subject: | Re: Converting a MySQL result into a complex array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156166@lists.php.net to get a copy of this message | ||
* Thus wrote jwulff (johnw@orcasnet.com):
> How would I take the results of the following MySQL statement and put it
> into an array as follows?
>
> SELECT * FROM numbers WHERE type=
1;
> SELECT * FROM numbers WHERE type=2;
>
> $example_data = array(
> array("1",25,8),
> array("2",10,8)
> );
Do you mean:
$example_data = array (
1 => array(25,8),
2 => array(10,8)
)
So thus you can access the data like
$example_data[1]; //access type 1 records.
$example_data[2]; //access type 2 records.
Now of course what and how you store the items in there is another
thing, is it just an array of one value? or an array of array's?
if its the first then you can just do something like
select type, number_field from numbers
for each row in the database:
$example_data[$row['type']][] = $row['number_field'];
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."