Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F3460476058 for ; Wed, 6 Nov 2002 04:44:06 -0500 (EST) Received: from mail.ramcargroup.com (unknown [202.58.114.60]) by postgresql.org (Postfix) with ESMTP id E6C41476009 for ; Wed, 6 Nov 2002 04:44:04 -0500 (EST) Received: from menusys.net (gw [192.168.0.10]) by mail.ramcargroup.com (Postfix) with ESMTP id D2D396B1D5; Wed, 6 Nov 2002 17:43:55 +0800 (PHT) Message-ID: <3DC8E482.6DA169A@menusys.net> Date: Wed, 06 Nov 2002 17:44:34 +0800 From: "Rommel B. Abaya" X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: Andrew McMillan Cc: Kelvin Varst , pgsql-php@postgresql.org Subject: Re: Column names References: <1036569603.8328.23.camel@kant.mcmillan.net.nz> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/23 X-Sequence-Number: 1605 $result = pg_exec($conn,"select * from table"); if (pg_numrows($result)) { for($i=0;$i".pg_fieldname($result,$i)."\n"; } } HTH Andrew McMillan wrote: > On Sun, 2002-11-03 at 22:26, Kelvin Varst wrote: > > Hi, > > > > When I make a simple "SELECT * FROM table;" query, is there somewhere in > > that query I can find the names of the columns? > > In PHP if you get the rows with: > > $row = pg_Fetch_Object( $result, $rownum); > > You will be able to refer to them by name as $row->fieldname > $row->otherfield and so on. > > This is very useful :-) > > Otherwise, if you want to know the column names, something like: > > SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM > pg_class WHERE relname = 'mytable') AND attnum > 0 ORDER BY attnum; > > will get them for you. > > Regards, > Andrew. > -- > --------------------------------------------------------------------- > Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington > WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St > DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267 > Survey for nothing with http://survey.net.nz/ > --------------------------------------------------------------------- > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly