RE: [PHP] mysql_fetch_array to associative array
| From: | Robert Cummings | Date: | Mon, 16 Jul 2007 20:45:43 +0000 |
| Subject: | RE: [PHP] mysql_fetch_array to associative array | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258954@lists.php.net to get a copy of this message | ||
On Mon, 2007-07-16 at 13:37 -0700, Andras Kende wrote:
>
> Hi Rob,
>
> Thanks for your help, its associative but I forget to mention its needs
> To be a single dimensional associative array.
>
>
> $result = array();
> while ( $row = mysql_fetch_assoc($get) ) {
> $result[] = $row;
> }
>
> This creates multi dimensional like:
>
> Array ( [0] => Array ( [0] => 3 [1] => BMW ) [1] => Array ( [0] => 1 [1] =>
> Mercedes ) )
>
> I tried to play with foreach and array_push but still not perfect
I'm not sure I understand... you have multiple rows being returned do
you not? How to you intend to handle them in a single level array?
Let's image the following rows are returned from the database:
array
(
'title' => 'The Dragonbone Chair',
'author' => 'Tad Williams',
),
array
(
'title' => 'Sword of Shannarah',
'author' => 'Terry Brooks',
),
Show me how you would like the final array to look and I can figure out
the code you need to organize it the way you want.
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................