pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tom <tom@outervention.net>
To: 'Pgsql-php \(E-mail\)' <pgsql-php@postgresql.org>
Subject: RE: Multi-dimensional arrays
Date: Wed, 20 Jun 2001 13:58:39 -0400
Message-ID: <002001c0f9b2$a3355450$7f0f2c81@bellsouth.net> (raw)
In-Reply-To: <59358A738F45D51186A30008C74CE2500A07A3@slc-exc1.ctron.com>

Multi-dimensional arraysfor($I=0;
$row=pg_fetch_array($result,$I,PGSQL_ASSOC); $I++){
    $resultArray[]=$row; // Results in a scalar array with nested
associative arrays
}
return $resultArray;


You could also go a step further and manipulate each element of $row inside
the for loop, with another loop:

for( ... ){
    while(list($key, $val)=each($row)){
        // play with each field element here...
    }
}


That said, my personal preference is to do it in a while loop instead of a
for loop, I think there was some reason why PHP preferred this, although I
can't remember why offhand.


$I=0;
while($I < pg_numrows($result)){
    $row=pg_fetch_array($result,$I,PGSQL_ASSOC);
    $resultArray[]=$row;
    $I++;
}
return $resultArray;





   -----Original Message-----
  From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org]On Behalf Of Hunter, Ray
  Sent: Wednesday, June 20, 2001 11:47 AM
  To: Pgsql-php (E-mail)
  Subject: [PHP] Multi-dimensional arrays


  Is there any way to get the result from a query into a multi-dimensional
array that can be done in a for loop.





  RAY HUNTER
  Automated Test Group
  Software Support Engineer

  ENTERASYS NETWORKS

  Internal:     53888
  Phone:       801 887-9888
  Fax:          801 972-5789
  Cellular:      801 698-0622
  E-mail:       rhunter@enterasys.com

  www.enterasys.com

view thread (2+ messages)

Message-ID: <002001c0f9b2$a3355450$7f0f2c81@bellsouth.net>
Permalink:  ../002001c0f9b2$a3355450$7f0f2c81@bellsouth.net/
Also on:    postgresql.org/message-id/002001c0f9b2$a3355450$7f0f2c81@bellsouth.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: tom@outervention.net
  Subject: Re: Multi-dimensional arrays
  In-Reply-To: <002001c0f9b2$a3355450$7f0f2c81@bellsouth.net>
  References: <59358A738F45D51186A30008C74CE2500A07A3@slc-exc1.ctron.com> <002001c0f9b2$a3355450$7f0f2c81@bellsouth.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox