Received: from smtp6ve.mailsrvcs.net (smtp6vepub.gte.net [206.46.170.27]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5KI17a35531 for ; Wed, 20 Jun 2001 14:01:07 -0400 (EDT) (envelope-from tom@outervention.net) Received: from masque (adsl-129-44-15-127.albny.adsl.bellatlantic.net [129.44.15.127]) by smtp6ve.mailsrvcs.net (8.9.1/8.9.1) with SMTP id SAA33601319 for ; Wed, 20 Jun 2001 18:01:04 GMT Reply-To: From: "tom" To: "'Pgsql-php \(E-mail\)'" Subject: RE: Multi-dimensional arrays Date: Wed, 20 Jun 2001 13:58:39 -0400 Message-ID: <002001c0f9b2$a3355450$7f0f2c81@bellsouth.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0021_01C0F991.1C23B450" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) In-Reply-To: <59358A738F45D51186A30008C74CE2500A07A3@slc-exc1.ctron.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000 Importance: Normal X-Archive-Number: 200106/46 X-Sequence-Number: 443 This is a multi-part message in MIME format. ------=_NextPart_000_0021_01C0F991.1C23B450 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit 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 ------=_NextPart_000_0021_01C0F991.1C23B450 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Multi-dimensional arrays
for($I=3D0; $row=3Dpg_fetch_array($result,$I,PGS= QL_ASSOC);=20 $I++){
    $resultArray[]=3D$row; // Res= ults in a=20 scalar array with nested associative arrays
}
return=20 $resultArray;
 
 
You=20 could also go a step further and manipulate each element of $row inside the= for=20 loop, with another loop:
 
for(=20 ... ){
    while(list($key,=20 $val)=3Deach($row)){
        // pl= ay with=20 each field element here...
    }
}
 
 
That=20 said, my personal preference is to do it in a while loop instead of a for l= oop,=20 I think there was some reason why PHP preferred this, although I can't reme= mber=20 why offhand.
 
 
$I=3D0;
while($I <= =20 pg_numrows($result)){
   =20 $row=3Dpg_fetch_array($result,$I,PGSQL_ASSOC);<= /DIV>
    $resultArray[]=3D$row;
   =20 $I++;
}
return $resultArray;
 
 
 
 
 
 -----Original=20 Message-----
From: pgsql-php-owner@postgresql.org=20 [mailto:pgsql-php-owner@postgresql.org]On Behalf Of Hunter,=20 Ray
Sent: Wednesday, June 20, 2001 11:47 AM
To: Pgsql= -php=20 (E-mail)
Subject: [PHP] Multi-dimensional=20 arrays

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


 
 
 
RAY HUNTER
Automated Test Group
So= ftware=20 Support Engineer
 
ENTERASYS NETWORKS
 
Internal:     53888
Phone:       801 887-9888= =20
Fax:          801= =20 972-5789
Cellular:      801 698-0622
= E-mail:      =20 rhunter@enterasys.com
 =20
www.enterasys.com
=20

------=_NextPart_000_0021_01C0F991.1C23B450--