Re: Recordsets and associative arrays
| From: | Adam Royle | Date: | Tue, 18 Feb 2003 05:23:54 +0000 |
| Subject: | Re: Recordsets and associative arrays | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-25711@lists.php.net to get a copy of this message | ||
Hi Don,
Use this process:
<?php
// create an empty array to fill with data
$data = array();
$row = 0;
while ($r = mysql_fetch_assoc($result)){
foreach ($r as $key => $value){
$data[$row][$key] = $value;
}
$row++;
}
?>
The array structure would be something like this:
$data[0]['Name'] = 'Name 1';
$data[0]['Address'] = 'Address1';
$data[0]['City'] = 'City1';
$data[1]['Name'] = 'Name 2';
$data[1]['Address'] = 'Address2';
$data[1]['City'] = 'City2';
$data[2]['Name'] = 'Name 3';
$data[2]['Address'] = 'Address3';
$data[2]['City'] = 'City3';
etc etc
HTH Adam
----- Original Message -----
Message-ID: <20030217224323.99345.qmail@pb1.pair.com>
To: php-db@lists.php.net
From: "Don Briggs" <donbriggs@donbriggs.com>
Date: Mon, 17 Feb 2003 16:42:51 -0600
Subject: Recordsets and associative arrays
Hello.
I am having a problem with syntax. Here is what I am doing. I have the
follwing table
|Name |Address |City |
=====================
|Name 1 | Address1 | City1 |
|Name 2 | Address2 | City2 |
|Name 3 | Address3 | City3 |
|Name 4 | Address4 | City4 |
=====================
I can fetch a single record into an associative array. But I need to put
these records into an multi-dimentional associatave array. I have tried to
figure out what the syntax should be, but it has not worked. The only thing
is that the key names will be different from the field names, and we won't
be putting all of the record fields into the table. So we can't just make an
array of the associative arrays returned by mysql_fetcharray($result). Hope
you can help me out.
Don!