On Wednesday 28 August 2002 15:31, Jean-Christian Imbeault wrote:
> I have the following loop to insert data into an array:
>
> while ($data = pg_fetch_object($res)) {
> $aProds[] = array('id' => $data->prod_id, 'quantity' =>
> $data->quantity);
> }
>
> But when I print this out using print_r I get the following:
>
> Array
> (
> [0] => Array
> (
> [0] => Array
> (
> [id] => 289000100024
> [quantity] => 1
> )
>
> [1] => Array
> (
> [id] => 289000100050
> [quantity] => 1
> )
>
> )
>
> )
>
> This array has only one element in it; not what I wanted. I wanted
> something like this:
>
> Array
> (
> [0] => Array
> (
> [id] => 289000100024
> [quantity] => 1
> )
> [1] => Array
> (
> [id] => 289000100050
> [quantity] => 1
> )
> )
>
> How can I achieve this?
If $aProds can contain more than 1 item then what you're doing now is correct.
If $aProds will only ever contain 1 item then use:
$aProds = array('id' => $data->prod_id, 'quantity' => $data->quantity);
But then you can drop the while-loop and probably can just do:
$aProds = pg_fetch_object($res);
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
Q: What is the difference between a duck?
A: One leg is both the same.
*/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php